Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Preface 1
Introduction 2
i
APIs 50
Application Life Cycle 51
Standard ASP Application Life Cycle 52
Android Application Life Cycle 53
ii
Chapter 7 :Using Intents and the Phone Dialer 123
What Are Intents? 125
Using the Dialer 131
Placing a Call from Your Activity 136
Adding the Intent to Your Activity 136
Editing Activity Permissions 139
Modifying the AndroidPhoneDialer 145
Adding a Button 145
Implementing an EditText View 151
Try This: Modify the AndroidPhoneDialer Project 155
iii
Getting the nmea File in Linux 220
Reading the GPS with the Android Location-Based API 223
Creating the AndroidLBS Activity 223
Passing Coordinates to Google Maps 233
Adding Zoom Controls 237
Try This : Toggling Between MapView's Standard
and Satellite Views 244
iv
Chapter 12 :Android SDK Tool Reference 317
Android Emulator Commands 318
Android Debug Bridge Commands 321
v
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Preface
နိဒါနး့
မ္ကးပျငးံစာေပ 1
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Introduction
Android: Programmer Guide မြ ႀကိဳဆိုပါသညး၈ ယခုစာအုပးသညး Mobile Developer တစးဦ့ကို
အလြ္ငးအ်မနးႏြငးံအခ္ိနးတိုတုိအတျငး့တျငး ေနရာစဵုမြ စဥး့စာ့ေတျ့ေခၚတတးေစရနး လိုအပးေသာ ပထမ
အဆငးံကိုလမး့ညႊနးေပ့ထာ့ပါသညး၈ Android ဆိုသညးမြာ ေနာကးဆဵု့ေပၚ Mobile device မ္ာ့တျငး
အသဵု့်ပဳေသာ Operating System တစးခု်ဖစးၿပီ့ ထိုသို႕ေသာ OS ကိုအေ်ခခဵ၍ Application မ္ာ့တညး
ေဆာကးရနးအတျကးယခုစာအုပးမြ အေကာငး့ဆဵု့အေထာကးအပဵံ်ဖစးေစမညး်ဖစးပါသညး၈
2 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Android Application မ္ာ့ကို Java တျငး Develop ်ပဳလုပးၿပီ့ Linux 2.6 kernel တျငးေမာငး့ႏြငးပါသညး၈
အခနး့ (ဿ) တျငး Eclipse IDE (Integrated development environment) ကို မညးကဲံသို႕ Download
်ပဳလုပးသညးဟူေသာအခ္ကးႏြငးံ Install ်ပဳလုပးရမညး႕ အဆငးံမ္ာ့ကိုေဖား်ပေပ့ထာ့ပါသညး၈ Android
Application မ္ာ့နမူနာတညးေဆာကးရာတျငးလအ
ို ပးေသာ Code မ္ာ့ႏြငးံ ပဵုမ္ာ့ကို ်ပညး႕စဵုစျာ်ဖငးံေဖား်ပ
ထာ့ပါသညး၈ ယခုစာအုပးပါ နမူနာ Application မ္ာ့တညးေဆာကးရာတျငး Eclipse ႏြငးံ Eclipse အတျကး
ဦ့တညး်ပဳလုပးထာ့ေသာ Android Plugin ကိုအသဵု့်ပဳပါသညး၈ လိုအပးေသာ ပစၥညး့ပစၥယ Tool မ္ာ့အာ့
လဵု့ကို ယခုစာအုပးႏြငးံပူ့တျဲပါ DVD ေချထဲတျငးထညး႕သျငး့ေပ့ထာ့ၿပီ့်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 3
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
4 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 1
What Is Android?
မ္ကးပျငးံစာေပ 5
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
6 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 7
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
8 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 9
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Linux, Windows ႏြငးံ PalmOS ကဲံသို႕ OS မ္ာ့ကိုအသဵု့်ပဳေသာ Cell Phone မ္ာ့ မ္ာ့်ပာ့စျာေတျ႕ရိြရ
ခ္ိနးတျငး Android ်ဖငးံေမာငး့ႏြငးႏိုငးေသာ မညးသညး႕ Hardware ပစၥညး့မ္ာ့ကိုမြ ထုတးလုပးေၾက်ငာခဲံ်ခငး့
မရိြခဲံပါ၈ သို႕ရာတျငး LG Electronics, Motorola ႏြငးံ Samsung ကဲံသို႕ေသာ ကုမၸဏီႀကီ့မ္ာ့ Open
Handset Alliance အဖျဲ႕၏ အဖျဲ႕ွငးမ္ာ့်ဖစးလာခ္ိနးတျငး Android Development သညးလညး့ တရိြနးထို့
တို့တကးသျာ့ခဲံေသားလညး့ ဿွွ၄ခုႏြစး ႏိွ
ု ငးဘာလတျငးမူ Android သညး Software Beta အဆငးံသာ
ရိြခဲံပါသညး၈ ယေန႕တျငး Android သဵု့ Handset မ္ာ့ကိုေတျ႕်မငးေနရၿပီ်ဖစးကာ မ္ာ့စျာေသာ ကုမၸဏီမ္ာ့
မြလညး့ Android ကိုအသဵု့်ပဳရနး Hardware ပစၥညး့မ္ာ့လညး့ ထုတးလုပးေနၾကၿပီ်ဖစးပါသညး၈
Introduction to Android
Android ဆိုသညးမြာ Java အေ်ခ်ပဳ Operting System တစးခု်ဖစးၿပီ့ linux 2.6 kernel ေပၚတျငးေမာငး့
ႏြငးပါသညး၈ အဆိုပါ System သညးအလျနးေပါံပါ့ၿပီ့ Feature မ္ာ့်ဖငးံလညး့ ်ပညး႕စဵုပါသညး၈ ေအာကးတျငး
ေဖား်ပထာ့ေသာပဵုတျငး မ်ပငးဆငးထာ့ေသာ Android Home Screen ကိုေတျ႕်မငးၾကရမညး်ဖစးပါသညး၈
10 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
12 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 2
Downloadng and Installing Eclipse
မ္ကးပျငးံစာေပ 13
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
14 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Why Eclipse?
Eclipse ကို Android Application မ္ာ့အတျကး အသဵု့်ပဳသငးံသညး႕ IDE အ်ဖစးသတးမြတးရ်ခငး့မြာ
ေအာကးေဖား်ပပါ အခ္ကးမ္ာ့ေၾကာငးံ ်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 15
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
16 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 17
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
18 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Java SE Previous Release Download Page ေပၚတျငး J2SE 5.0 ဟူေသာ Download link ကို Click
ႏိြပး၍ အလိုရိြေသာ JDK 5.0 Update x ေဘ့မြ Download ခလုတးကိုတစးခ္ကးႏိြပးေပ့ပါ၈ ယခုေနရာမြ x
သညး ေနာကးဆဵု့ထျကး update number အ်ဖစးမြတးယူရပါမညး၈
မ္ကးပျငးံစာေပ 19
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
20 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
အထကးပါပဵအ
ု တိုငး့ Java SDK ကို Install ်ပဳလုပးၿပီ့ေသာအခါ JRE ကိုပါ တစးပါတညး့ Install ်ပဳလုပးၿပီ့
်ဖစးသညး႕အတျကး Eclipse ကိုစတငးအသဵု့်ပဳႏိုငးၿပီ်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 21
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
22 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Double Click ႏိြပး၍ ေမာငး့ႏြငးေပ့ရပါမညး၈ ထိုအခါ User directory (folder) ေအာကးတျငး Eclipse ကို
Install ်ပဳလုပးသျာ့မညး်ဖစးၿပီ့ ေအာကးေဖား်ပပါပဵုအတိုငး့ Eclipse Spendist Screen ေပၚလာသညးက
ေတျ႕်မငးရမညး်ဖစးသညး၈
မ္ကးပျငးံစာေပ 23
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Use this as the default and do not ask again ဟူေသာ Check Box ကိုသာေရျ့ခ္ယးအမြနး်ခစးေပ့
ထာ့ခဲံပါက အာ့လဵု့ေသာ Application Project မ္ာ့ကို ေဖား်ပပါ Workspace ထဲတျငးသာ သိမး့ဆညး့
မညး်ဖစးၿပီ့ ေနာကးတစးႀကိမးထပးမဵေရျ့ခ္ယးခိုငး့ေတာံမညးမဟုတးပါ၈ ထို႕ေၾကာငးံအဆိုပါ Check Box ကို
ေရျ့ခ္ယးရနးအႀကဵ်ပဳလိုပါသညး၈ ထို႕ေနာကး ေရျ့ခ္ယးစရာမ္ာ့ကို ေရျ့ခ္ယးၿပီ့ပါက OK ကို Click ႏိြပးေပ့ရပါ
မညး၈
24 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter3
Downloading and Installing the
Android SDK
မ္ကးပျငးံစာေပ 25
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Android SDK ကိုစတငး Download ်ပဳလုပးရနးအတျကး Google Android Development Site ်ဖစးေသာ
http://code.google.com/android သို႕သျာ့ေရာကးရပါမညး၈ Home Page တျငးပငး Android Platform
အတျကးအသဵု့ွငးေစမညး႕ Tool မ္ာ့၇ Document မ္ာ့အ်ပငး Android developer forum ်ဖငးံ
ခ္ိတးဆကးႏိုငးရနး Community ်ပဳလုပး်ခငး့တို႕ကိုပါေဆာငးရျကးေစႏိုငးမညး်ဖစးပါသညး၈ ေအာကးတျငး
Google Android Development ၏ Home Page ကိုေဖား်ပေပ့ထာ့ပါသညး၈
26 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 27
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
28 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
၀၈ ထို႕ေနာကး Install/Update Window တျငး Search for New Features to install ဟူေသာ Radio
button ကိုေရျ့ခ္ယးၿပီ့ေနာကး Next တျငး Click ႏိြပးပါ၈
မ္ကးပျငးံစာေပ 29
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
30 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
၄၈ ထို CheckBox ကိုအမြနး်ခစးေပ့၍ေရျ့ခ္ယးၿပီ့ Finish တျငး Click ႏိြပးပါ၈ Eclipse သညး ရိုကးထညး႕ထာ့
ေသာ URL ႏြငးံ သကးဆိုငးေသာ Web Site တျငး Download လုပးယူႏိုငးေသာ Plugin မ္ာ့ကိုရြာေဖျေပ့
မညး်ဖစးပါသညး၈
၆၈ ေအာကးေဖား်ပပါအတိုငး့ Lincese Page ေပၚလာေသာအခါ Accept ကိုေရျ့ခ္ယး၍ Next ကို Click ႏိြပး
ေပ့ရပါမညး၈
မ္ကးပျငးံစာေပ 31
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
ှွ၈ ထို႕ေနာကး Eclipse သညး Android Plugin ကို Download ်ပဳလုပးေနမညး်ဖစးပါသညး၈ ထို႕ေနာကး
ေအာကးတျငးေဖား်ပထာ့သညး႕ပဵုအတိုငး့ Feature Verification Page ေပၚလာေသာအခါတျငး Install All
ဟူေသာ ခလုတးကိုေရျ့ခ္ယး၍ Installation ၿပီ့ဆဵု့သညးအထိ ေစာငးံဆိုငး့ရပါမညး၈
32 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ှ၈ Eclipse ၏ Main Windows မြ Windows Menu ကို Click ႏိြပးၿပီ့ ထိုမြ Preferences ကိုေရျ့ခ္ယးပါ၈
မ္ကးပျငးံစာေပ 33
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
၀၈ ထို႕ေနာကး Automatically sync projects to Current SDK ဟူေသာ Check Box ကိုအမြနး်ခစးေပ့
ေရျ့ခ္ယး၍ Apply ခလုတးတျငး Click တစးခ္ကးႏိြပးေပ့ရပါမညး၈ သတိထာ့ရနးအခ္ကးမြာ SDK Location
တျငး ေရျ့ခ္ယးရနး Download ်ပဳလုပးထာ့သညး႕ Android SDK သညး Zip ဖိုငး်ဖစးေနတတးေသာေၾကာင
SDK Location တျငး မေရျ့ခ္ယးမီတျငး အဆိုပါ Zip ဖိုငးကို Extract ်ပဳလုပး၍ ရရိြလာေသာ Folder ကိုသာ
ေရျ့ခ္ယးသတးမြတးေပ့ရပါမညး၈ ထို႕အ်ပငး ရရိြလာေသာ Folder ၏အမညးမြာလညး့ ရြညးလြ္ာ့လြ၍
ႏြစးသကးရာ အဆငးေ်ပမညးနာမညးတစးခုခုသို႕ေ်ပာငး့လဲသငးံပါသညး၈ မေ်ပာငး့လဲဘဲ ထိုအတိုငး့အသဵု့်ပဳ
ကလညး့ ်ပသနာမရိြပါ၈
34 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 35
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
36 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 4
Exploring the Android SDK
မ္ကးပျငးံစာေပ 37
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Android SDK တျငး ဖုနး့ေခၚဆိုလကးခဵ်ခငး့တို႕အ်ပငး GPS function မ္ာ့ႏြငးံ Text Message ကဲံသို႕ေသာ
Cel Phone function မ္ာ့ႏြငးံသကးဆိုငးေသာ Core Android Feature မ္ာ့ႏြငံးသကးဆင
ုိ းေသာ Library
မ္ာ့ပါွငးပါသညး၈ အဆိုပါ Library မ္ာ့်ဖငးံ SDK ၏ Coreကိုတညးေဆာကးထာ့်ခငး့်ဖစးၿပီ့ ယခုအခနး့တျငး
အဆိုပါ အေၾကာငး့အရာမ္ာ့ကို ေလံလာရမညး်ဖစးပါသညး၈ ယခုအခနး့တျငး Android SDK တျငး ပါွငး
ေသာ အေရ့ႀကီ့သညး႕အစိတးအပိုငး့မ္ာ့ကို ေဖား်ပေပ့မညး်ဖစးသညး၈ ယခုအခနး့ကို ေသခ္ာစျာေလံလာ
်ခငး့်ဖငးံ Android SDK၏ Content မ္ာ့အေၾကာငး့ကို က္နစျာသိရိြသျာ့မညး်ဖစးၿပီ့ Android
Programming ကိုေရ့သာ့ရာတျငးပိုမို ကၽျမး့က္ငးလာေစမညး်ဖစးသညး၈ Android Application ကိုစတငး
မေရ့သာ့မီတျငး ၁ငး့ႏြငးံသကးဆိုငးေသာ Content မ္ာ့ႏြငးံ လုပးေဆာငးခ္ကးမ္ာ့ႏြငးံ ရငး့ႏီြ့ကၽျမး့က္ငးရနး
လိုအပးေသာေၾကာငးံ ယခုေဖား်ပပါအခနး့ကို ေသခ္ာစျာေလံလာေစလိုပါသညး၈
Android Documentation
Android Documentation ကို Android SDK ၏ Docs Folder အတျငး့တျငး ထညး႕သျငး့ထာ့ပါသညး၈ ထို
Documentation တျငး SDK ကို Download ်ပဳလုပး်ခငး့ႏြငးံ Install ်ပဳလုပး်ခငး့ႏြငးံသကးဆိုငးေသာ
အေၾကာငး့အရာမ္ာ့အ်ပငး Application မ္ာ့ကို Develop လုပးယူရနးအတျကး Gettings Started ဟူေသာ
အေၾကာငး့အရာႏြငးံ Package ဖျငးံဆုိခ္ကးမ္ာ့ပါွငးပါသညး၈ အဆိုပါ Documentation ကို HTML Format
်ဖငးံေရ့သာ့ထာ့ၿပီ့ SDK Folder ၏ Root folder မြ documentation.html ဖိုငးကိုဖျငံး်ခငး့်ဖငးံ ဖတးရြဳႏိုငး
ပါသညး၈ ေအာကးတျငးေဖား်ပထာ့ေသာပဵုသညး ထို documentation.html ကို ဖျငးံလုိကး်ခငး့်ဖငးံ ေတျ႕်မငး
ရမညး႕ပဵုပငး်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 39
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Reference Information
Class Index
List of Permissions
List of Resource Types
Troubleshooting
40 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Android Samples
Android SDK ၏ Samples ဟူေသာ Folder အတျငး့တျငး နမူနာ Application ေ်ခာကးခုပါွငးၿပီ့ ထိုနမူနာ
Application မ္ာ့ကိုေလံလာေစႏိုငးပါသညး၈ ထိုနမူနာ Application မ္ာ့မြာေအာကးပါအတိုငး့်ဖစးပါသညး၈
API Demos
Hello, Activity!
Lunar Lander
Note Pad
Skeleton App
Snake
API Demos
API Demos Application သညး Host Application တစးခု်ဖစးၿပီ့ Activity တစးခုတညး့တျငး API
function မ္ာ့ကို သဵု့စျဲ်ခငး့စသညးတို႕ကို ရြငး့လငး့ေဖား်ပထာ့ပါသညး၈ Activity ဆိုသညးမြာ Android
Application တစးခုဟုသာအၾကမး့်ဖငး့နာ့လညးထာ့ရမညး်ဖစးၿပီ့ ထို Activity မ္ာ့အေၾကာငး့ကို ေနာကး
ပိုငး့ အခနး့မ္ာ့တျငး အေသ့စိပးရြငး့လငး့ေဖား်ပထာ့ပါသညး၈
မ္ကးပျငးံစာေပ 41
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
အဆိုပါ API Demos နမူနာ Application တျငး 3D image transistions၇ list and progress dialog
boxes ႏြငးံ finger-painting demo ကဲံသို႕ေသာ Application အခ္ိဳ႕ကိုလညး့ ထညး႕သျငး့ေပ့ထာ့သည
ကိုလညး့ေတျ႕ရပါသညး၈
Try This
(အိမးစာ) Run the API Demos Sample Application
Eclipse ကိုအသဵု့်ပဳ၍ API Demos ဟူေသာ Application ကို New Android Project အ်ဖစး Load ်ပဳ
လုပးၾကညး႕ပါမညး၈ ထိုသို႕်ပဳလုပးရနးအတျကး Eclipse ၏ File Menu မြ New ထိုမြ Project ကိုေရျ့ခ္ယးေပ့
ပါ၈ ထိုအခါ New Android Project Wizard ပျငးံလာသညးကိုေတျ႕ရမညး်ဖစးသညး၈ Wizard
တျငးပါွငးေသာ Option မ္ာ့ကိုနာ့လညးေနစရာမလိုေသ့ဘဲ Existing Source မြ Create Project
ကိုသာေရျ့ခ္ယးေပ့ရမညး်ဖစးသညး၈ ထို႕ေနာကး Browse ကိုႏိြပး၍ API Demo application ကို ေရျ့ခ္ယး
ေပ့ရပါမညး၈ Project ကို Load ်ပဳလုပးၿပီ့ေသာအခါတျငး Run ကိုေရျ့ခ္ယး၍ Android Emulator တျငး
ေမာငး့ႏြငး်ခငး့ကိုေတျ႕ရိြရမညး်ဖစးပါသညး၈ Application တိုငး့ကို ဖျငးံၾကညး႕ၿပီ့ Terminal ႏြငးံ API tool
မ္ာ့၏ လုပးေဆာငးခ္ကးမ္ာ့်ဖငးံ ရငး့ႏီြ့လာေစရနး ်ပဳလုပးေပ့သငးံပါသညး၈
42 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Hello, Activity!
Lunaer Lander
မ္ကးပျငးံစာေပ 43
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Lunar Lander သညး UP, Down, Left ႏြငးံ Right ကဲံသို႕ေသာ ရို့ရြငး့ေသာ Control မ္ာ့ကိုသာ
အသဵု့်ပဳထာ့ပါသညး၈ ၁ငး့တျငး fluid graphic ႏြငးံဆကးစပးေသာ ်မငးကျငး့ကိုေဖား်ပေပ့ၿပီ့ ေပ့ထာ့ေသာ
Platform အတျကးခ္ီ့က္ဴ့ဖျယးရာပငး်ဖစးပါသညး၈ Collision Detection ကဲံသို႕ေသာ ရႈပးေထျ့ေသာ Game
သီအိုရီမ္ာ့ကိုလညး့ ရို့ရြငး့ေသာနညး့လမး့်ဖငးံ အသဵု့်ပဳထာ့ပါသညး၈ ယခုစာအုပးတျငး Android Platform
အတျကး Game မ္ာ့ေရ့သာ့်ခငး့ကို ေဖား်ပမညးမဟုတးေသားလညး့ အကယး၍စိတွ
း ငးစာ့ပါက ထို Lunar
Lander Application ကိုေလံလာၾကညး႕ေစလိုပါသညး၈ Android ၏ Game Development ကိစ
ု ိတွ
း ငးစာ့
ပါက ေနာကးပိုငး့ထျကးရိြလာမညး႕ Android Game Development အေၾကာငး့ေရ့သာ့ထာ့ေသာ စာအုပး
ကိုေလံလာႏိုငးမညး်ဖစးပါသညး၈
Notepad
44 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Skeleton App
Skeleton App သညး Application Shell တစးခု်ဖစးၿပီ့ သာမနးအေ်ခခဵ Application ထကးပိုမိုအဆငးံ်မင
သာလျနးပါသညး၈ ၁ငး့တျငး Font မ္ာ့၇ Button မ္ာ့၇ Image မ္ာ့ႏြငးံ Form မ္ာ့ကဲံသို႕ေသာ ကျဲ်ပာ့သညး႕
Application Feature မ္ာ့ကိုအသဵု့်ပဳထာ့ပါသညး၈ အကယး၍ သူ႕အတိုငး့သာ ေမာငး့ႏြငးၾကညး႕မညးဆို
လြ္ငး မညးကဲံသို႕ Code မ္ာ့ေရ့သာ့ထာ့သညးဆိုေသာအခ္ကးကို လိုကးမီႏိုငးမညးမဟုတးပါ၈ ထို႕ေၾကာငးံ
skeleton App ၏ေရ့သာ့ပဵုကိုေလံလာ်ခငး့်ဖငးံ item တစးခုစီ၏အလုပးလုပးေဆာငးပဵုကို ေသခ္ာစျာ သိရိြ
ေစႏိုငးမညး်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 45
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Snake
Android SDK တျငးပါွငးေသာ ေနာကးဆဵု့ demo application မြာ Snake ်ဖစးပါသညး၈ ထို Application
သညးေသ့ငယး၍ SNAFU style ်ဖစးေသာ ဂိမး့ဆစးခု်ဖစးၿပီ့ Lunar Lander ႏြငးံႏႈိငး့ယြဥးလြ္ငး ပိုမိုရို့ရြငး့
ပါသညး၈ ေအာကးတျငးေဖား်ပထာ့ေသာပဵုတျငး Emulator တျငး Snake ကိုေမာငး့နြငး်ခငး့်ဖငးံ ေတျ႕ရိြရမညး႕
ပဵုပငး်ဖစးပါသညး၈
Android Tools
Andorid SDK သညး Developer မ္ာ့ကို အသဵု့ွငးေစေသာ Tool အမ္ာ့အ်ပာ့ကို ေထာကးပဵံေပ့ပါသညး၈
ယခုအပိုငး့တျငးထို Tool မ္ာ့အေၾကာငး့ကို အနညး့ငယးေလံလာၾကညး႕ရမညး်ဖစးပါသညး၈ ထို Tool မ္ာ့ထဲ
မြတစးခု်ဖစးေသာ Command-Line Development အေၾကာငး့ကိုလာမညး႕အခနး့တျငး အက္ယးတွငးံေလံ
လာရဦ့မညး်ဖစးပါသညး၈
46 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Emulator.exe
မ္ကးပျငးံစာေပ 47
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
adb.exe
MKSDCARD.exe
အကယး၍ SD Memory Card ကို Mobile Device အတျငး့သို႕ထညး႕သျငး့၍ file မ္ာ့ Read သို႕မဟုတး
Write ်ပဳလုပးရနးလိုအပးေသာ Application တစးခုခုကိုစမး့သပးရနးလိုအပးခဲံပါက MKSDCARD.exe သညး
အလျနးအသဵု့ွငးေသာ Tool တစးခုအ်ဖစး လုပးေဆာငးေပ့ပါသညး၈ MKSDCARD.exe သညး Partation
အေသ့တစးခုကိုဖနးတီ့ေပ့ၿပီ့ file မ္ာ့ကိုစမး့သပး သိမး့ဆညး့ရနးလိုအပးသညး႕အခါ ထို Partation ကို
Emulator မြ SD Memory Card ကဲံသို႕ထငး်မငးေအာငး ်ပဳလုပးေပ့ႏိုငးပါသညး၈
DX.exe
DX.exe သညး Android SDK ၏ Compiler တစးခု်ဖစးပါသညး၈ ေရ့သာ့ထာ့ေသာ Java File မ္ာ့ကို
ေမာငး့ႏြငးေသာအခါ DX.exe သညး Dalvik executable format ်ဖစးေသာ .dex extension ဖိုငးမ္ာ့ကို
တညးေဆာကးေပ့ႏိုငးပါသညး၈ ထိုဖုိငးမ္ာ့သညး Android Device မြ ေမာငး့ႏြငးႏိုငး၇ နာ့လညးႏိုငးေသာ
မြနးကနးသညး႕ Format လညး့်ဖစးပါသညး၈ Android မြေမာငး့ႏြငးႏိုငးေသာ ဖိုငးမ္ာ့ကို Dalvik executable
file မ္ာ့ဟုေခၚၿပီ့ ၁ငး့ဖိုငးမ္ာ့သညး Android မြအသဵု့်ပဳၿပီ့အာ့လဵု့ေသာ Application မ္ာ့ကို အသဵု့်ပဳႏိုငး
ေစသညး႕ Dalvik virtual mahine သို႕်ပဳလုပးသညး႕ Reference တစးခုသဖျယးအ်ဖစးလညး့ လုပးေဆာငး
ေစပါသညး၈
activityCreator(.bat or .pn)
မ္ကးပျငးံစာေပ 49
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
APIs
API သို႕မဟုတး Application Programming interface မ္ာ့သညးAndroid SDK ၏ Core ပငး်ဖစးပါသညး၈
API တစးခုသညး function မ္ာ့၇ Method မ္ာ့၇ Properties မ္ာ့၇ Class မ္ာ့ႏြငးံ Library တို႕၏ အစုအေွ့
်ဖစးၿပီ့ သတးမြတးထာ့ေသာ Platform မ္ာ့ေပၚတျငး အလုပးလုပးေဆာငးႏိုငးေသာ Program မ္ာ့ေရ့ဆျဲရနး
အတျကး Application Developer မ္ာ့အတျကး အသဵု့်ပဳရသညး႕ ဖိုငးမ္ာ့လညး့်ဖစးပါသညး၈ Android API
တျငး သတးမြတးထာ့ေသာ အခ္ကးအလကးမ္ာ့အာ့လဵု့ပါွငးၿပီ့ Application မ္ာ့တညးေဆာကး၍ Android
အေ်ခ်ပဳ Application မ္ာ့အ်ဖစး လုပးေဆာငးႏိုငးေစပါသညး၈ Android SDK တျငး API ႏြစးမ္ိဳ့ႏြစးစာ့ကို
ေထာကးပဵံေပ့ထာ့ၿပီ့ ၁ငး့တို႕မြာ Google API မ္ာ့ႏြငးံ Optional API မ္ာ့ ်ဖစးသညး၈ ေနာကးပိုငး့တျငး ၁ငး့
အေၾကာငး့အရာမ္ာ့ကို ပိုမိုအေသ့စိပးေလံလာရမညး်ဖစးၿပီ့ ယခုအခနး့တျငးမူ အၾကမး့်ဖငး့သာေလံလာ
ၾကညး႕ၾကပါမညး၈
Google APIs
50 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Google API တျငး Prtocol အသစး်ဖစးေသာ Extensible Messaging and Presence Protocol (XMPP)
ကိုယူသဵု့ႏိုငးေစမညး႕ အသဵု့ွငးသညး႕ Package မ္ာ့လညး့ ပါွငးပါေသ့သညး၈ အဆိုပါ XMPP ကုိ Jabber
Open Source Community မြ Develop ်ပဳလုပးထာ့်ခငး့်ဖစးပါသညး၈ XMPP ကိုအသဵု့်ပဳ်ခငး့်ဖငးံ
အ်ခာ့ေသာအသဵု့်ပဳသူမ္ာ့ကိုေတျ႕်မငးရေစၿပီ့ Message ႏြငးံ Communication တို႕ကိုလညး့ လုပးေဆာငး
ချငးံေပ့ထာ့ပါသညး၈ XMPP ႏြငးံသကးဆိုငးေသာ API package မ္ာ့သညး အကယး၍ Chat လုပး်ခငး့ကဲံသို႕
ေသာ Application မ္ာ့ေရ့ဆျဲသညး႕အခါတျငး အလျနးအသဵု့ွငးေစပါသညး၈
Optinal APIs
Cycle တစးခုတျငး Execution မြ Termination သို႕ follow လုပးႏိုငးေသာ Application Processes မ္ာ့၏
အဆငးံမ္ာ့ပငး်ဖစးပါညး၈ Application တိုငး့ (မညးသညး႕ Language ်ဖငးံေရ့သာ့သညး်ဖစးေစ) တျငး ၁ငး့
ႏြငးံသကးဆိုငးေသာ Life Cycle မ္ာ့ရိြၾကၿပီ့ Android Application မ္ာ့သညးလညး့ ထို႕အတူပငး်ဖစးပါ
သညး၈ ယခုအပိုငး့တျငး Android Application မ္ာ့၏ Life Cycle ်ဖငးံႏိႈငး့ယြဥးေလံလာႏိုငးရနးအတျကး ASP
application မ္ာ့၏ life cycle ်ဖငးံယြဥးတျဲေလံလာၾကညး႕ၾကပါမညး၈
1. Application_Start
2. Event
3. HTTPApplication.Init
4. Disposal
5. Application_End တို႕်ဖစးပါသညး၈
1. onCreate
2. onStart
3. Process-specific events (ဥပမာ- Activity အမ္ာ့အ်ပာ့ကို launch လုပး်ခငး့ႏြငးံ database
တစးခုသို႕ွငးေရာကး်ခငး့)
4. onStop
5. onDestroy တို႕်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 53
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
54 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 5
Application: Hello World!
မ္ကးပျငးံစာေပ 55
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
56 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 57
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
မြာ New Menu မြ Java Project ကိုမေရျ့ခ္ယးမိရနး်ဖစးသညး၈ Android Application မ္ာ့ကို ေရ့သာ့ရာ
တျငး Java ကိုအသဵု့်ပဳရ်ခငး့်ဖစးေသားလညး့ ထိုကဲံသို႕ Java Project ကိုေရျ့ခ္ယးမိ်ခငး့်ဖငးံ Standard
Java Application တစးခုကိုစတငးေစမညး်ဖစးေသာေၾကာငးံပငး်ဖစးသညး၈ ထို႕ေၾကာငးံ Android Project ကို
သာေရျ့ခ္ယးပါမြ Android ်ဖငးံသကးဆိုငးေသာ Application မ္ာ့ကိုေရ့သာ့ႏိုငးမညး်ဖစးသညး၈
အကယး၍ Android Project ဟူေသာ Option ကုိသာမ်မငးေတျ႕ခဲံရပါက Eclipse အတျကးလိုအပးေသာ
Android Plugin ကို ်ပညး႕စဵုစျာ Install မ်ပဳလုပးထာ့၍ ်ဖစးပါသညး၈ ထို႕ေၾကာငးံ ထိုအခ္ကးကုိ ေ်ဖရြငး့
ႏိုငးရနးအတျကး Android Plugin ကို Install ်ပဳလုပးရနး လိုအပးမညး်ဖစးပါသညး၈
အထကးတျငးေရျ့ခ္ယးလိုကးေသာ New Android Project Wizard တျငး လုပးေဆာငးခ္ကးအရာႏြစးခုက
်ပဳလုပးေပ့မညး်ဖစးသညး၈
- Android.jar ဟူေသာ ဖိုငးကိုအသဵု့်ပဳ်ခငး့်ဖငးံ Android SDK ်ဖငးံသကးဆိုငးေသာ shell
application တစးခုကို ဖနးတီ့မညး်ဖစးၿပီ့ အဆိုပါ application သညး Android Emulator ႏြငးံ
သကးဆိုငးေသာ project လညး့်ဖစးပါသညး၈ ၁ငး့သညး အာ့လဵု့ေသာ Android Library မ္ာ့ႏြငးံ
Package မ္ာ့ကို အသဵု့်ပဳ၍ Code ေရ့သာ့ချငးံရိြမညး်ဖစးၿပီ့ Proper Environment တျငး
ေရ့သာ့ထာ့ေသာ Application မ္ာ့ကို Debug လညး့ ်ပဳလုပးေစႏိင
ု းမညး်ဖစးပါသညး၈
58 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
- ်ပဳလုပးမညး႕ Project အသစးအတျကး Shell File မ္ာ့်ဖငးံ စတငးရနး်ဖစးသညး၈ အဆိုပါ Shell ဖိုငး
မ္ာ့တျငး တညးေဆာကးလိုကးေသာ Program မ္ာ့ေပၚမူတညးကာ vital application application
အခ္ိဳ႕ပါွငးလာမညး်ဖစးသညး၈ Visual Studio အတျငး့ Microsoft.Net application ေရ့သာ့ရာ
တျငး Windows မြ file မ္ာ့အတျငး့ Program Code ဖနးတီ့သကဲံသို႕ပငး Android Project
Wizard ကိုအသဵု့်ပဳ၍ Eclipse သညး ကနဦ့ Program file မ္ာ့ႏြငးံ Android Code အခ္ိဳ႕ကို
ထုတးေပ့မညး်ဖစးသညး၈
New Android Project Wizard ၏ေနာကးဆဵု့ Option သဵု့ခုမြာ Properties Area တျငးတညးရိြပါသညး၈ ထို
Properties မ္ာ့သညး Project ကို Android environment အတျငး့တျငး မညးကဲံသို႕ integrate ်ပဳလုပး
မညးဆိုသညး႕အခ္ကးကို ညႊနး့ဆိုပါသညး၈ Package Name filed တျငး ်ပဳလုပးမညး႕ application package
သို႕ namespace ကို ရညးညႊနး့ရနးအတျကး အသဵု့်ပဳႏိုငးပါသညး၈ ဥပမာအာ့်ဖငးံ android.app.Activity
သို႕မဟုတး com.google.android.map.MapActivity စေသာနာမညးမ္ာ့်ဖငးံသတးမြတးထာ့ႏိုငးပါသညး၈
60 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
62 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
AndroidManifest.xml
AndroidManifest.xml ဟူေသာဖိုငးသညး global setting မ္ာ့ကိုစုစညး့ထာ့ေသာဖိုငး်ဖစးသညး၈
အကယး၍ ASP.Net ကိသ
ု ာအသဵု့်ပဳဖူ့လြ္ငး အဆိုပါ AndroidManifest.xml ဖိုငးသညး Web.config ႏြငးံ
Global.asax ဖိုငးႏြငးံအလာ့တူသ႑နးတူေၾကာငး့သတိ်ပဳမိပါလိမးံမညး၈ အရြငး့ဆဵု့ဆုိရလြ္င
AndroidManifest.xml ဖိုငးတျငး application permission ႏြငးံသကးဆိုငးေသာ Setting မ္ာ့၇ Activity
မ္ာ့ႏြငးံ intent filter မ္ာ့ကို စုစညး့ထာ့ေသာဖိုငးတစးဖိုငး်ဖစးေၾကာငး့ သိရိြထာ့ရပါမညး၈
မ္ကးပျငးံစာေပ 63
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Referenced Libaries
Reference ်ပဳလုပးထာ့ေသာ Library မ္ာ့၏ စာရငး့သညး Project ၏ Root Directory ထဲတျငးတစးခါ
တညး့ပူ့တျဲပါွငးၿပီ့ ်ဖစးပါသညး၈ ပဵုမြနးအာ့်ဖငးံ သာမနးရို့ရို့ Project အတျကး Library တစးခုတညး့ကိုသာ
ေတျ႕်မငးရမညး်ဖစးၿပီ့ ထို Referenced Library မ္ာ့ကို ်ဖနး႕ခ္ၿပီ့ ပါွငးေသာ Content မ္ာ့ကို စစးေဆ့ရပါ
မညး၈ Library မ္ာ့သညး ေလာေလာလတးလတးေရ့သာ့ေနေသာ Android Project ကို Reference
်ပဳလုပးေစရနးအေရ့ႀကီ့ပါသညး၈ Android Project တစးခုကိုစတငးသညးႏြငးံ Project Reference တစးခု
အ်ပငး၇ android.jar ဖိုငးႏြငးံ Android SDK တို႕ကို ေတျ႕်မငးေနၾက်ဖစးပါလိမးံမညး၈ ထိုသို႕ Reference
Library မ္ာ့ကို Android Plugin မြ်ပဳလုပးေပ့်ခငး့်ဖစးပါသညး၈ ထို႕အ်ပငး ေရ့သာ့မညး႕ Android သညး
SDK Library မ္ာ့အတျငး့မြ Views, Control ႏြငးံ Google API စေသာ Class မ္ာ့ကို
ွငးေရာကးသဵု့စျဲႏိုငးေစရနးအလို႕ငြါ Android SDK ကိုပါ Reference ်ပဳလုပးထာ့ရနးလိုအပးပါမညး၈
Eclipse သညးအဆိုပါ Built-In ပါရိြေသာ Library မ္ာ့အ်ပငး အ်ခာ့ေသာ User-defined Library မ္ာ့ႏြငးံ
်ပငးပ Class မ္ာ့ကိုပါ ေရ့သာ့မညး႕ Project အတျကး Reference ်ပဳလုပးချငးံေပ့ထာ့ပါသညး၈ သို႕ရာတျငး
64 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Directories
Android Project တစးခု၏ Root Directory ထဲတျငး Directory သဵု့ခုရိြၿပီ့ ၁ငး့တို႕မြာ res, assets ႏြငးံ src
တို႕်ဖစးၿပီ့ ၁ငး့တို႕ကို မတူညီေသာ ရညးရျယးခ္ကးမ္ာ့အတျကးအသဵု့်ပဳေလံရိြပါသညး၈ Directory တစးခုစီ
သညး ေရ့ဆျဲမညး႕ Application ၏ လုပးေဆာငးခ္ကးမ္ာအတျကး အဓိကအခနး့က႑မြပါွငးသညး႕အတျက
အေရ့ႀကီ့သညးဟုသတးမြတးႏိုငးပါသညး၈
Res Directory
မ္ကးပျငးံစာေပ 65
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
assets Directory
src Directory
R.java File
66 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
R.java file သညး ေရ့သာ့ေနသညး႕ Android application အတျကး android plugin မြအလိုအေလြ္ာကး
ထညး႕သျငး့ေပ့လိုကးေသာဖိုငးတစးဖိုငး်ဖစးပါသညး၈ ယငး့ဖိုငးတျငး Drawable,layout ႏြငးံ values ဟူေသာ
directory မ္ာ့အတျကးအသဵု့်ပဳရသညး႕ Pointer မ္ာ့ပါွငးပါသညး၈ ထို႕ေၾကာငးံ ထိုဖုိငးကိုမညးသညး႕အခါ
တျငးမြ တိုကးရိုကး်ပငးဆငး်ခငး့ မ်ပဳလုပးႏိုငးပါ၈ မ္ာ့ေသာအာ့်ဖငးံ ေရ့သာ့သညး႕ Application မ္ာ့အတျကး
သာလြ္ငး Reference ်ပဳလုပးေလံရိြပါသညး၈ ယခုေအာကးတျငးေဖား်ပထာ့ေသာ Code မ္ာ့သညး
HelloWorldText ဟူေသာ Application အတျကး Android Plugin မြအလိုအေလြ္ာကး ထုတးေပ့လိုက
ေသာ Code မ္ာ့်ဖစးပါသညး၈
package testPackage.HelloWorldText;
<activity>.java File
package android_programmers_guide.HelloWorldText;
import android.app.Activity;
import android.os.Bundle;
68 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
onCreate() ဟူေသာ method သညး bundle တစးခုအ်ဖစး icicle ကိုလုပးေဆာငးေစပါသညး၈ ထိုအခါ အာ့
လဵု့ေသာလကးရိြ State information မ္ာ့ကို icicle object တစးခုအ်ဖစး Memory အတျငး့သို႕ စုစညး့ေစ
ပါသညး၈ ၁ငး့၏ ပါွငး်ခငး့ႏြငးံ ရညးရျယးခ္ကးကိုသိရိြရနးလိုအပးေသားလညး့ Application အတျငး့တျငး icicle
ကို တိုကးရိုကးအသဵု့်ပဳႏိုငးစျမး့မရိပ
ြ ါ၈
setContentView(R.layout.main);
ြsetContentView () ဟူေသာ method သညး main.xml ကို Current View အေန်ဖငးံ အစီအစဥးခ္ထာ့
သညးဟုယူဆလြ္ငး main.xml တျငး “Hello World, HelloWorldText” ဟုေဖား်ပေပ့ႏိုငးေသာ TextView
တစးခု ပါွငးေၾကာငး့ သတိ်ပဳမိၾကပါမညး ထငးပါသညး၈ အဆိုပါ ေ်ပာငး့လဲ်ပငးဆငးထာ့်ခငး့မရိြသညး႕
HelloWorldText Application ကိုစမး့သပးေမာငး့ႏြငးၾကညး႕ၾကပါမညး၈ ထိုသို႕ေမာငး့ႏြငးရနး Run Menu မြ
Run သို႕ ေရျ့ခ္ယးေပ့်ခငး့်ဖငးံ ေအာကးတျငးေဖား်ပထာ့သညး႕ပဵုအတိုငး့ Run As Dialogbox ေပၚလာမည
်ဖစးၿပီ့ Android Application တျငးေရျ့ခ္ယး၍ OK ကို Click ႏိြပးပါ၈
မ္ကးပျငးံစာေပ 69
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, HelloWorldText"
/>
70 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 71
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, HelloWorldText"
/>
</LinearLayout>
setContentView(R.layout.main);
72 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
import android.widget.TextView;
HelloWorldTextView.setText("Hello World!");
မ္ကးပျငးံစာေပ 73
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
setContentView(HelloWorldTextView);
package android_programmers_guide.HelloWorldText;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
74 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ထို႕ေနာကး အသစး်ပဳလုပးထာ့ေသာ Hello World! Application ကို Android Emulator တျငး Complile
်ပဳလုပးေမာငး့ႏြငးၾကညး႕ပါမညး၈ ထိုသို႕်ပဳလုပးရနး Run Menu မြ Run သို႕မဟုတး Keyboard မြ Short-cut
Key ်ဖစးေသာ Ctrl+F11 ကိုတျဲႏိြပး်ခငး့်ဖငးံ Android Emulator တျငး Application ကိုေဖား်ပလာေစမညး
်ဖစးသညး၈ ေပၚလာမညး႕ပဵုကိုေအာကးတျငးေဖား်ပထာ့ပါသညး၈
မ္ကးပျငးံစာေပ 75
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
76 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 77
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
ထို႕ေနာကး R.java ဖိုငးကိုဖျငးံ၍ Code မ္ာ့ကိုၾကညး႕ပါ၈ Eclipse သညး helloworld.png ဖိုငးကို pointer
တစးခုအေန်ဖငးံ ေပါငး့ထညး႕ထာ့သညးကို ေအာကးတျငးေဖား်ပထာ့ေသာ Code အရ သိရိြႏိုငးပါသညး၈
package android_programmers_guide.HelloWorldImage;
78 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
import android.widgets.ImageView;
မ္ကးပျငးံစာေပ 79
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
HelloWorldImageView.setImageResource(R.drawable.helloworld);
setContentView(HelloWorldImageView);
package android_programmers_guide.HelloWorldImage;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
/**Hello World Image JFD*/
/**BEGIN */
/**Create the ImageView */
ImageView HelloWorldImageView = new ImageView(this);
/**Set the ImageView to helloworld.png */
HelloWorldImageView.setImageResource(R.drawable.helloworld);
/**Set the ContentView to the ImageView */
setContentView(HelloWorldImageView);
/**END */
}
}
80 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 81
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
package android_programmers_guide.HelloWorldImage;
import android.app.Activity;
import android.os.Bundle;
public class HelloWorldImage extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
}
}
<ImageView
/>
android:id="@+id/imageview"
82 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/helloworld"
<ImageView android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/helloworld"
/>
setContentView(R.layout.main);
ထို႕ေနာကး HelloWorldImage ဖိုငးကို Compile ်ပဳလုပး၍ Run ပါ၈ ထျကးလာမညး႕ Screen ၏ပဵုကို
ေအာကးတျငးေဖား်ပထာ့ပါသညး၈
မ္ကးပျငးံစာေပ 83
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
84 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 85
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
86 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 6
Using the Command-Line Tools and
the Android Emulator
မ္ကးပျငးံစာေပ 87
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
@echo off
rem Copyright (C) 2007 Google Inc.
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
မ္ကးပျငးံစာေပ 89
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
"%~dp0\lib\activityCreator\activityCreator.exe" %*
ထို႕ေၾကာငးံ Start Menu > Run သို႕သျာ့ေရာကးကာ ေပၚလာေသာ Run Box တျငး cmd ဟုရိုကးထညး႕
ကာ OK ကို Click ႏိြပးပါ၈ (အကယး၍ Run ကိုရြာမေတျ႕ပါက Window +R ကိုတျဲႏိြပးပါ၈)
90 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Command Prompt interface သညး Default အာ့်ဖငးံ Case Sensitive (အကၡရာအႀကီ့အေသ့ ကျာ
်ခာ့်ခငး့မရိြပါ) မ်ဖစးေသားလညး့ Linux/ Unix System ကိုအသဵု့်ပဳသညး႕အခါတျငး Case Sensitive ်ဖစး
သညးကို နာ့လညးသိရိြထာ့ရပါမညး၈ ActivityCreator.bat ကို ေမာငး့ႏြငးေစမညး႕ ActivityCreator ဟူ
ေသာ Command ကိုေမာငး့ႏြငးၾကညး႕ေသာအခါတျငး ေအာကးေဖား်ပပါ Output ကို Screen တျငးေတျ႕်မငး
ရမညး်ဖစးပါသညး၈
Options:
--out <folder>: specifies where to create the files/folders.
--ide intellij: creates project files for IntelliJ
မ္ကးပျငးံစာေပ 91
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
--out c:\AndroidHelloWorld\android_programmers_guide.HelloWorldCommandLine
--out ဟူေသာ Option သညး တစးစဵုတစးရာကို Output ထုတးေပ့ရနးအတျကး ActivityCreator ကို ေ်ပာ်ပ
ေပ့ႏိုငးပါသညး၈ ထို Command Option တျငး Paramter ႏြစးခုရိြၿပီ့ <folder> ႏြငံး <package.activity>
တို႕်ဖစးပါသညး၈ ေဖား်ပခဲံၿပီ့ေသာ Command အရ AcitivityCreator ကို မရိြေသ့ေသာ Folder ်ဖစးေသာ
C:\AndroidHelloWorld တျငး Shell Application တစးခုကို ်ပဳလုပးေပ့ႏိုငးပါသညး၈ သတိ်ပဳရနးမြာ
တညးေဆာကးခိုငး့သညး႕ Project ရိြမညး႕ Folder ကို မ်ပဳလုပးရေသ့လြ္ငး ActivityCreator မြ အလို
အေလြ္ာကး်ပဳလုပးေပ့ႏိုငးပါသညး၈ --out option ၏ ဒုတိယ Parameter မြာ Package name ႏြငးံ activity
name တို႕်ဖစးပါသညး၈ ယခငးအခနး့တျငးေဖား်ပခဲံၿပီ့်ဖစးေသာ အမညးမ္ာ့ကိုယူသဵု့မညး်ဖစးေသာေၾကာင
ယခု Project အတျကး package name တျငး android_programmers_guide ဟုသတးမြတးေပ့ၿပီ့
Activity name ကို HelloWorldCommandLine ဟုသတးမြတးေပ့ရပါမညး၈
92 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 93
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
ANT အတျကး Android application ကို Compile ်ပဳလုပးရတျငး အသဵု့်ပဳရနးအတါကး build.xml ဖိုငးကို
တညးေဆာကးပါသညး၈ ထိုဖိုငးကို အထကးတျငးေဖား်ပခဲံၿပီ့ေသာ ပဵုအတိုငး့ပငး Project ထာ့ရိြေသာ Root
Directory အတျငး့တျငး ရြာေဖျေတျ႕ရိြႏိုငးပါသညး၈ ထို build.xml ဖိုငးကို text editor တစးခုခု်ဖငးံ ဖျငးံ၍
ေရ့သာ့ထာ့ေသာ Code မ္ာ့ကို ၾကညး႕ႏိုငးပါသညး၈ build.xml ဖိုငး၏ ပထမပိုငး့တျငး အသဵု့်ပဳသူ user
မ္ာ့မြ ်ပငးဆငးႏိုငးေသာ Code မ္ာ့ပါွငးပါသညး၈ ထိုဖိုငးမြ ်ပငးဆငးႏိုငးေသာ အပိုငး့ကို ေအာကးတျငးေဖား်ပ
ထာ့ၿပီ့ ထိုဖိုငးမြအ်ခာ့ေသာ Code မ္ာ့ကို်ပငးဆငးႏိုငးချငးံမရိြေသာေၾကာငးံ ေဖား်ပ်ခငး့မ်ပဳေတာံပါ၈
94 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Build.xml ဖိုငး၏ ပထမ Section တျငး ေအာကးတျငးေဖား်ပထာ့ေသာ Properties မ္ာ့အတျကး Value မ္ာ့
ပါွငးပါသညး၈
Project name
Android SDK location
Android tools location
Android framework location
Output Location တို႕်ဖစးသညး၈
မ္ကးပျငးံစာေပ 95
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
ကိုေကာငး့မျနးစျာနာ့လညးသိရိြထာ့ခဲံပါကေအာကးတျငးေဖား်ပထာ့သညး႕မေ်ပာငး့လဲသငးံေသာ Parameter
မ္ာ့ကိုပါ မိမိလိုအပးခ္ကးႏြငးံကိုကးညီေအာငးအထိ ်ပငးဆငးႏိုငးပါသညး၈
<!-- Create the output directories if they don't exist yet. -->
<target name="dirs">
<mkdir dir="${outdir}" />
<mkdir dir="${outdir-classes}" />
</target>
<!-- Generate the R.java file for this project's resources. -->
<target name="resource-src" depends="dirs">
<echo>Generating R.java...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="compile" />
<arg value="-m" />
<arg value="-J" />
<arg value="${outdir-r}" />
<arg value="-M" />
<arg value="AndroidManifest.xml" />
<arg value="-S" />
<arg value="${resource-dir}" />
<arg value="-I" />
96 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<!-- Compile this project's .java files into .class files. -->
<target name="compile" depends="dirs, resource-src, aidl">
<javac encoding="ascii" target="1.5" debug="true" extdirs=""
srcdir="."
destdir="${outdir-classes}"
bootclasspath="${android-jar}" />
</target>
<!-- Convert this project's .class files into .dex files. -->
<target name="dex" depends="compile">
<exec executable="${dx}" failonerror="true">
<arg value="-JXmx384M" />
<arg value="--dex" />
<arg value="--output=${basedir}/${intermediate-dex}" />
<arg value="--locals=full" />
<arg value="--positions=lines" />
<arg path="${basedir}/${outdir-classes}" />
</exec>
</target>
<!-- Put the project's resources into the output package file. -->
<target name="package-res-and-assets">
<echo>Packaging resources and assets...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="package" />
<arg value="-f" />
<arg value="-c" />
<arg value="-M" />
<arg value="AndroidManifest.xml" />
<arg value="-S" />
<arg value="${resource-dir}" />
<arg value="-A" />
<arg value="${asset-dir}" />
<arg value="-I" />
<arg value="${android-jar}" />
<arg value="${out-package}" />
</exec>
</target>
မ္ကးပျငးံစာေပ 97
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<!-- Put the project's .dex files into the output package file.
Use the zip command, available on most unix/Linux/MacOS systems,
to create the new package (Ant 1.7 has an internal zip command,
however Ant 1.6.5 lacks it and is still widely installed.)
-->
<target name="package-dex" depends="dex, package-res">
<echo>Packaging dex...</echo>
<exec executable="${zip}" failonerror="true">
<arg value="-qj" />
<arg value="${out-package}" />
<arg value="${intermediate-dex}" />
</exec>
</target>
<!-- Create the package file for this project from the sources. -->
<target name="package" depends="package-dex" />
98 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<!-- Create the package and install package on the default emulator -->
<target name="install" depends="package">
<echo>Sending package to default emulator...</echo>
<exec executable="${adb}" failonerror="true">
<arg value="install" />
<arg value="${out-package}" />
</exec>
</target>
</project>
မ္ကးပျငးံစာေပ 99
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
import android.widget.TextView;
100 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ှ၈ Computer (My Computer) ကို Right Click ႏြိပၿး ပီ့ Properties ကိုေရျ့ခ္ယးပါ၈
မ္ကးပျငးံစာေပ 101
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
102 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
သို႕ွငးေရာကး၍ ant ဟူေသာ Command ကိုအသဵု့်ပဳ၍ Run ႏိုငးပါသညး၈ Project Directory အတျငး့
တျငး Command Prompt Window ကိုဖျငးံၿပီ့ ant ဟုရိုကးထညး႕၍ ေအာကးပါပဵုအတိုငး့ Run ႏိုငးပါသညး၈
ant Command ကို Run ်ခငး့်ဖငးံ .apk ဖိုငးရရိြလာမညး်ဖစးၿပီ့ Emulator အတျငး့ တိုကးရိုကး Install
်ပဳလုပးႏိုငးေသားလညး့ Eclipse ကိုအသဵု့်ပဳခဲံစဥးကလညး့ တိုကးရိုကး Install ်ပဳလုပးခဲံ်ခငး့်ဖစးေသာေၾကာင
ယခုေနရာတျငး Manual နညး့်ဖငးံသာ Install ်ပဳလုပးၾကညး႕ၾကပါမညး၈ ထိုသို႕်ပဳလုပးရနး Android Debug
Bridge (adb) Android Tool ကိုအသဵု့်ပဳရမညး်ဖစးၿပီ့ ေနာကးအပိုငး့တစးခုတျငး အသဵု့်ပဳပဵုမ္ာ့ကို ေဖား်ပ
ေပ့ထာ့ပါသညး၈
အကယး၍ Application Project ကို Run သညး႕အခါတျငး ANT Command မြ Error တစးခုကို ထုတးေပ့
ခဲံလြ္ငးလညး့ စို့ရိမးစရာမလိုပါ၈ ထိုသို႕ ထျကးလာႏိုငးသညး႕ Error ကိုေအာကးေဖား်ပပါပဵုတျငး ေဖား်ပထာ့ပါ
သညး၈
မ္ကးပျငးံစာေပ 103
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
104 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<!-- Create the output directories if they don't exist yet. -->
<target name="dirs">
<mkdir dir="${outdir}" />
<mkdir dir="${outdir-classes}" />
</target>
<!-- Generate the R.java file for this project's resources. -->
<target name="resource-src" depends="dirs">
<echo>Generating R.java...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="compile" />
<arg value="-m" />
<arg value="-J" />
<arg value="${outdir-r}" />
<arg value="-M" />
<arg value="AndroidManifest.xml" />
<arg value="-S" />
<arg value="${resource-dir}" />
<arg value="-I" />
<arg value="${android-jar}" />
</exec>
</target>
</fileset>
</apply>
</target>
<!-- Compile this project's .java files into .class files. -->
<target name="compile" depends="dirs, resource-src, aidl">
<javac encoding="ascii" target="1.5" debug="true" extdirs=""
srcdir="."
destdir="${outdir-classes}"
မ္ကးပျငးံစာေပ 105
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
bootclasspath="${android-jar}" />
</target>
<!-- Convert this project's .class files into .dex files. -->
<target name="package-dex" depends="dex, package-res">
<echo>Packaging dex...</echo>
<exec executable="${zip}" failonerror="true">
<!--<arg value="-Xmx384M" />-->
<!-- Move Xmx parameter to dx.bat - FIX - BLOCK END -->
<arg value="--dex" />
<arg value="--output=${intermediate-dex}" />
<arg value="--locals=full" />
<arg value="--positions=lines" />
<arg path="${outdir-classes}" />
</exec>
</target>
<!-- Put the project's resources into the output package file. -->
<target name="package-res-and-assets">
<echo>Packaging resources and assets...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="package" />
<arg value="-f" />
<arg value="-c" />
<arg value="-M" />
<arg value="AndroidManifest.xml" />
<arg value="-S" />
<arg value="${resource-dir}" />
<arg value="-A" />
<arg value="${asset-dir}" />
<arg value="-I" />
<arg value="${android-jar}" />
<arg value="${out-package}" />
</exec>
</target>
106 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<!-- Put the project's .class files into the output package file. -->
<target name="package-java" depends="compile, package-res">
<echo>Packaging java...</echo>
<jar destfile="${out-package}"
basedir="${outdir-classes}"
update="true" />
</target>
<!-- Put the project's .dex files into the output package file. -->
<target name="package-dex" depends="dex, package-res">
<echo>Packaging dex...</echo>
<exec executable="${zip}" failonerror="true">
<arg value="-qj" />
<arg value="${out-package}" />
<arg value="${intermediate-dex}" />
</exec>
</target>
<!-- Create the package file for this project from the sources. -->
<target name="package" depends="package-dex" />
</project>
မ္ကးပျငးံစာေပ 107
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Command Description
Install <path> Installs applications to the server
Pull <remote file><local file> Pulls a remote file off the server
Push <local file><remote file> Pushes a local file to the server
Shell Opens a shell environment on the server
Forward <local port><remote port> Forwards traffic from one port to another
(to and from the server)
Start-server Starts the server
Kill-server Stops the server
PPP <tty><params> Uses a PPP connection over USB
108 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 109
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
110 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 111
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
function မ္ာ့ကိအ
ု သဵု့်ပဳႏိုငးေသားလညး့ ယခုေနရာတျငး HelloWorldCommandLine.apk ဖိုငးအေဟာငး့
ကိုဖယးထုတးရနးအတျကးကိုသာအသဵု့်ပဳမညး်ဖစးပါသညး၈
Android Server ေပၚတျငး User မြ Install ်ပဳလုပးထာ့ေသာ Application မ္ာ့ကို /data/app ဟူေသာ
directory ေအာကးတျငးသိမး့ဆညး့ထာ့ပါသညး၈ CD Command ကိုအသဵု့်ပဳ၍ app directory သို႕
ေရာကးရိြေစရနး သျာ့ေရာကးရပါမညး၈ ေအာကးေဖား်ပပါပဵုတင
ျ း အသဵု့်ပဳရပဵုကိုေဖား်ပရြငး့လငး့ထာ့ပါသညး၈
ေရာကးရိြေနေသာ Directory အတျငး့မြ File မ္ာ့ကို List လုပးၾကညး႕ရြဳရနး ls ဟူေသာ Command ကို
အသဵု့်ပဳရပါသညး၈ ထိုအခါ HelloWorldCommandLine.apk ဖိုငးကိုေတျ႕်မငးရမညး်ဖစးပါသညး၈ ထိုဖုိငး
သညး Install ်ပဳလုပးထာ့ေသာ .apk ဖိင
ု း (Activity) ကိုကိုယးစာ့်ပဳပါသညး၈ ထို႕ေနာကး ထိုဖိုငးကို ဖ္ကးပစး
ၾကညး႕ၾကပါမညး၈ Application တစးခုကိုဖ္ကးရနးအသဵု့်ပဳရေသာ Command မြာ rm HelloWorld
CommandLine.apk ်ဖစးပါသညး၈ ေအာကးတျငးေဖား်ပထာ့ေသာပဵုတျငး rm ဟူေသာ Command ကိုအသဵု့
ဲ်ပဳ၍ HelloWorldCommandLine.apk ဖိုငးကိုဖ္ကးပစး်ခငး့ကို ေဖား်ပထာ့ေသာပဵု်ဖစးပါသညး၈ ေအာငး်မငးစျာ
ဖ္ကးပစးႏိုငးခဲံပါက မညးသညး႕ Feedback ကိုမြ္်မငးေတျ႕ရမညးမဟုတးပါ၈ ထို႕ေနာကး Ls Command ကို
ေနာကးတစးႀကိမး်ပနး Run ၍ အမြနးတကယး ဖ္ကးပစး်ခငး့ဟုတး၇မဟုတး စစးေဆ့ၾကညး႕ႏိုငးပါသညး၈
112 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 113
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
114 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
echo $PATH
ထို႕ေနာကး Path Statement အတျငး့သို႕ Android ကိုထညး႕သျငး့ရနး export ဟူေသာ Command ကို
အသဵု့်ပဳရပါမညး၈ ေအာကးေဖား်ပပါပဵုတျငး ေလံလာႏိုငးပါသညး၈
မ္ကးပျငးံစာေပ 115
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
116 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Linux အတျကး Android SDK သညး Python Script ်ဖငးံလာၿပီ့ activityCreator.py သညး Project
မ္ာ့ကိုတညးေဆာကးရနးအသဵု့်ပဳရပါမညး၈ Python Script ကိုေမာငး့ႏြငးေသာအခါတျငး ေရ့သာ့မညး႕
Project အတျကး Output directory ကိုတညးေဆာကးေပ့မညး်ဖစးပါသညး၈ သို႕ရာတျငး ကိုယးတိုငး
manual နညး့လမး့်ဖငးံလညး့ တညးေဆာကးႏုိငးပါသညး၈ ထိုသို႕တညးေဆာကးရနးအတျကး mkdir ဟူေသာ
Command ကိုအသဵု့်ပဳရပါမညး၈ ေအာကးပဵုတျငးေဖား်ပထာ့ပါသညး၈
မ္ကးပျငးံစာေပ 117
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
118 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 119
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
ထို႕ေနာကး Android Emulator ကိုစတငးၿပီ့ Application ကို Install ်ပဳလုပးရပါမညး၈ Emulator စတငး
Run ေသာအခါတျငး ေအာကးပါ Command ်ဖငးံ Application ကို Install ်ပဳလုပးႏိုငးပါသညး၈
Linux Android Server တျငး Application ကို Install ်ပဳလုပးၿပီ့ေနာကး Android Emulator အတျငး့တျငး
ေမာငး့ႏြငးၾကညး႕ႏိုငးၿပီ်ဖစးပါသညး၈ ေနာကးလာမညး႕အခနး့တျငး Phone Event မ္ာ့ကို Android SDK မြ
မညးကဲံသို႕အသဵု့်ပဳသညးဆိုေသာအေၾကာငး့အရာမ္ာ့ကို ေလံလာရပါမညး၈
120 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 121
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
122 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 7
Using Intents and the Phone Dialer
မ္ကးပျငးံစာေပ 123
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
124 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 125
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
126 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
DIAL_ACTION Open the Dial Acitivity and dial the specified number
(DEFAULT_ACTION)
WALLPAPER_SETTINGS_ACTION Show settings for modifying the Android Wallpaper
WEB_SEARCH_ACTION Open Google Search, or another web page if specified
မ္ကးပျငးံစာေပ 127
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
128 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 129
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
UMS_DISCONNECTED_ACTION The device has been disconnected from its USB host
ႈIntent မ္ာ့ႏြငးံ Intent Receiver မ္ာ့တျငး Activity တစးခုသညး Intent တစးခုကို ေပ့ပို႕ေနစဥးတျငး
အ်ခာ့ေသာ Intent တစးခုကို လကးခဵေစႏိုငးပါသညး၈ သို႕ရာတျငး ထိုသို႕လုပးေဆာငးရာတျငး Activity ႏြစး
ခုအၾကာ့ ေပ့ပို႕နိုငးေသာ Information အမ္ိဳ့အစာ့မ္ာ့ကို ထိနး့ခ္ဳပးႏိုငးေသာ တစးစဵုတစးရာကို လုိအပးပါ
လိမးံမညး၈ ၁ငး့လုပးေဆာငးခ္ကးကို Intent Filter မြလုပးေဆာငးေပ့ႏိုငးပါသညး၈ Intent Filter မ္ာ့ကို
Activity မ္ာ့မြ လကးခဵရရိြလိုေသာ Intent အမ္ိဳ့အစာ့မ္ာ့ကို ေဖား်ပရနး အသဵု့်ပဳပါသညး၈ ပိုမိုအေရ့ႀကီ့
ေသာအခ္ကးမြာ ၁ငး့သညး Intent ႏြငးံအတူ ်ဖတးသနး့သျာ့ေသာ Data အမ္ိဳ့အစာ့ကို ေဖား်ပရပါမညး၈
ထို႕ေၾကာငးံ အထကးတျငးေဖား်ပခဲံေသာ ဥပမာတျငး Web Browser ကို Web Page ကိုဖျငးံရနး လိုအပးခဲံ်ခငး့
130 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 131
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
import android.content.Intent;
import android.net.Uri;
132 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
DIAL_ACTION Intent သညး data ကို URI အ်ဖစးယူႏိုငးပါသညး၈ ထို႕ေၾကာငးံ Uri parse ကိုအသဵု့်ပဳၿပီ့
Phone Number ကိုသရုပးချဲေဖား်ပႏိုငးပါသညး၈ Uri parse ကိုအသဵု့်ပဳ်ခငး့်ဖငးံ DIAL_ACTION ဟူေသာ
Intent ကို ဖုနး့နဵပါတးတစးခု၏ ဖုနး့ေခၚဆိမ
ု ႈကိုနာ့လညးေစပါသညး၈ ဖုနး့ေခၚဆိုလိုေသာ ဖုနး့နဵပါတးတစးခုခု
ကို String အ်ဖစးသတးမြတး၍ Uri.parse ကို pass ်ပဳလုပးႏိုငးပါသညး၈ ယခုဥပမာတျငး ဖုနး့နဵပါတး
“tel:5551212” ကိုအသဵု့်ပဳမညး်ဖစးၿပီ့ ထိုဖုနး့နဵပါတးတျငးႏြစးသကးရာ ဖုနး့နဵပါတးတစးခုကိုအသဵု့်ပဳႏိုငးပါ
သညး၈ ထို႕ေနာကး ်ပဳလုပးထာ့ေသာ Intent အတျကး Code မ္ာ့ကိုေအာကးပါအတိုငး့ေတျ႕်မငးရမည
်ဖစးပါသညး၈
ဖနးတီ့ထာ့ေသာ Intent ႏြငးံအတူ Android ကို ဖုနး့နဵပါတးကို Dial ်ပဳလုပးေသာအခါတျငး Activity အသစး
တစးခုကို Launch ်ပဳလုပးရနးအတျကး Intent ၏ setLaunchFlags() ဟူေသာ method
ကိုအသဵု့်ပဳရပါမညး၈ launch ်ပဳလုပးရနးအတျကး setLaunchFlags() တျငးသငးံေတားေသာ parameter
ကိုအသဵု့်ပဳရပါ မညး၈ ေအာကးတျငးေဖား်ပထာ့ေသာ list တျငးအသဵု့်ပဳႏိုငးေသာ flag မ္ာ့ကို
ေဖား်ပထာ့ပါသညး၈
မ္ကးပျငးံစာေပ 133
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
DialIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH );
startActivity(DialIntent);
package android_programmers_guide.AndroidPhoneDialer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
public class AndroidPhoneDialer extends Activity {
/** Called when the Activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
/** Create our Intent to call the Dialer */
/** Pass the Dialer the number 5551212 */
Intent DialIntent = new
Intent(Intent.DIAL_ACTION,Uri.parse("tel:5551212"));
/** Use NEW_TASK_LAUNCH to launch the Dialer Activity */
DialIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH );
/** Finally start the Activity */
startActivity(DialIntent);
} }
134 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ထို႕ေနာကး AndroidPhoneDialer ကို compile ်ပဳလုပးၿပီ့ Emulator တျငး Run ႏိုငးၿပီ်ဖစးသညး၈ အဆိုပါ
Compile လုပးေဆာငးခ္ကးမ္ာ့ကို ယခငးအခနး့တျငးေဖား်ပခဲံၿပီ့်ဖစးသညး႕အတျကး ေကာငး့မျနးစျာလုပးေဆာင
ႏိုငးမညးဟု ထငးပါသညး၈ Application ကို Run ေစေသာအခါ Emulator ပျငးံလာၿပီ့ေနာကး ယခုေရ့သာ့
ထာ့ေသာ Acitity ကိုေတျ႕်မငးရမညး်ဖစးသညး၈
မ္ကးပျငးံစာေပ 135
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
import android.content.Intent;
import android.net.Uri;
136 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ထို႕ေနာကး Uri.parse ကိုအသဵု့်ပဳ၍ Telephone Number ကို Activity သို႕ မြနးကနးေသာ parse ်ဖငးံ
pass ်ပဳလုပးေပ့ရပါမညး၈ ေနာကးတစးဆငးံအရ Android ကို Activity ကို launch ်ပဳလုပးရနး ေ်ပာဆိုရ
မညး်ဖစးၿပီ့ Lauch ်ပဳလုပးပါမညး၈ ထိုအဆငးံကို ေအာကးပါ Code မ္ာ့ထညး႕သျငး့်ခငး့်ဖငးံ လုပးေဆာငးႏိုငး
ပါသညး၈
CallIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH );
startActivity(CallIntent);
ပထမ Code စာေၾကာငး့တျငး NEW_TASK_LAUNCH သို႕ lauch flag ကိုေပ့ပို႕ပါမညး၈ ၁ငး့သညး Call
Activity အသစးတစးခုကို launch ်ပဳလုပးေစပါလိမးံမညး၈ ေနာကးတစးေၾကာငး့တျငး Activity ကိုစတငးရနး
်ဖစးပါသညး၈ ထို Code စာေၾကာငး့မ္ာ့ကို ထညး႕သျငး့ၿပီ့ေနာကးတျငး AndroidPhoneDial.java ဖိုငးသညး
ေအာကးတျငးေဖား်ပထာ့သညး႕အတိုငး့ ်ဖစးလာပါမညး၈
package android_programmers_guide.AndroidPhoneDialer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
မ္ကးပျငးံစာေပ 137
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Application_Error:
…
Java.lang.SecurityException:
Permission Denial: starting Intent
…
138 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ACCESS_ASSISTED_GPS
ACCESS_CELL_ID
ACCESS_GPS
ACCESS_LOCATION
ACCESS_SURFACE_FLINGER
ADD_SYSTEM_SERVICE
BROADCAST_PACKAGE_REMOVED
BROADCAST_STICKY
CALL_PHONE
CHANGE_COMPONENT_ENABLED_STATE
DELETE_PACKAGES
DUMP
FOTA_UPDATE
GET_TASKS
INSTALL_PACKAGES
INTERNAL_SYSTEM_WINDOW
RAISED_THREAD_PRIORITY
READ_CONTACTS
မ္ကးပျငးံစာေပ 139
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
READ_FRAME_BUFFER
RECEIVE_BOOT_COMPLETED
RECEIVE_SMS
RECEIVE_WAP_PUSH
RUN_INSTRUMENTATION
SET_ACTIVITY_WATCHER
SET_PREFERRED_APPLICATIONS
SIGNAL_PERSISTENT_PROCESSES
SYSTEM_ALERT_WINDOW
WRITE_CONTACTS
WRITE_SETTINGS
140 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 141
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
ထို Windows တျငး လကးရိြ Activity အတျကး assign ်ပဳလုပးထာ့ေသာ Permission မ္ာ့ကိုေဖား်ပေန
မညး်ဖစးသညး၈ အထကးပါပဵုတျငး Project အသစးႏြငးံအလုပးလုပးေဆာငးေနသညး႕အတျကး မညးသညး႕
Permission ကိုမြ္ သတးမြတးထာ့်ခငး့မရိြေၾကာငး့ေတျ႕ရပါမညး၈ ထို႕ေၾကာငးံ လုပးေဆာငးခ္ကးကိုစတငးရန
Add ခလုတးတျငး Click ႏိြပးပါ၈ Dialogbox တစးခုပျငးံလာေသာအခါတျငး Uses Permission ကိုေရျ့ခ္ယး၍
OK ကို Click ႏိြပးပါ၈ ထိုအခါ Android Manifest Permission Window သို႕်ပနးေရာကးလာၿပီ့ Name ဟူ
ေသာ drop-down list တျငး android.permission.CALL_PHONE ကိုေရျ့ခ္ယးရပါမညး၈ ေအာကးတျငး
ေဖား်ပထာ့ေသာပဵုတျငး ်ပထာ့ပါသညး၈ ထိုစာေၾကာငး့ကိုေရျ့ခ္ယး်ခငး့်ဖငးံ ေရ့သာ့ေနသညး႕ Activity
အတျကး CALL_PHONE permission ကိုထညး႕သျငး့ေပ့်ခငး့်ဖစးပါသညး၈
142 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
စိတွ
း ငးစာ့ဖျယးအေကာငး့ဆဵု့ Code စာေၾကာငး့မြာ ေအာကးပါ Code ပငး်ဖစးပါသညး၈
<uses-permission android:name="android.permission.CALL_PHONE">
</uses-permission>
မ္ကးပျငးံစာေပ 143
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Permission ကို Assign ်ပဳလုပးသတးမြတးၿပီ့ေနာကး Activity ကို Recompile ်ပနးလုပး၍ Run ်ပနးလုပး
ၾကညး႕ပါ၈ Emulator တျငး Phone Call တစးခုေခၚဆိုေနေၾကာငး့ကို ေအာကးပါပဵုအရ ေတျ႕်မငးႏိုငးမညး
်ဖစးပါသညး၈
တညးေဆာကးခဲံေသာ Activity တျငး Call Activity ကို Launch ်ပဳလုပးရနး Intent တစးခုကို အသဵု့်ပဳခဲံပါ
သညး၈ အထကးပါဥပမာတျငး Intent တစးခုကို အက္ိဳ့ရိြရိြအသဵု့်ပဳခဲံ်ခငး့ကိုေဖား်ပခဲံပါသညး၈ သို႕ရာတျငး
အဆိုပါ Application တျငးလကးေတျ႕လုပးေဆာငးရေသာ လုပးေဆာငးခ္ကးအနညး့ငယး ပါ ပါသညး၈
ေနာကးလာမညး႕အပိုငး့တျငး ပိုမိုလကးေတျ႕က္ေသာ application မ္ာ့တညးေဆာကးၾကညး႕ၾကမညး်ဖစးၿပီ့
ခလုတးတစးခုထညး႕သျငး့တညးေဆာကး၍ Call_Action ကိုပါ တစးပါတညး့အသဵု့်ပဳၾကညး႕ပါမညး၈ ထို႕အ်ပငး
144 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Adding a Button
ယခုအပးိုငး့တျငး Button တစးခုထညး႕သျငး့အသဵု့်ပဳ၍ မညးသို႕်ပငးဆငးမညးကို ေလံလာရပါမညး၈ Activity
ကို စတငးသညးႏြငးံ Intent ကိုအလုပးေစမညး႕အစာ့၇ Button ကိုႏိြပးေသာအခါတျငးမြ Intent ကိုလုပး
ေဆာငးေစရနး ်ပငးဆငးပါသညး၈ Text မ္ာ့၇ Button မ္ာ့သညး မညးသညး႕ Application တျငးမဆို အသဵု့
အမ္ာ့ဆဵု့ေသာ Object မ္ာ့်ဖစးပါသညး၈ Button မ္ာ့သညး အသဵု့်ပဳသူႏြငးံ Application အၾကာ့တျငး
ကူ့လူ့စျာဆကးသျယးမႈေပ့ေသာ Object တစးခုလညး့်ဖစးပါသညး၈ Button ႏြငးံ ၁ငး့ Button ၏အလုပး
လုပးေဆာငးပဵုကိုေလံလာ်ခငး့်ဖငးံ လကးေတျ႕က္ေသာ၇ အသဵု့ွငးေသာ Activity တစးခုကိုတညးေဆာကးႏိုင
မညး်ဖစးပါသညး၈ Button ကိုတညးေဆာကးရနးအတျကး main.xml သို႕ွငးေရာကး၍ တညးေဆာကးရပါမညး၈
အခနး့ (၂) တျငးေဖား်ပခဲံေသာ Hello World! Activity အတျကး TextView တညးေဆာကးခဲံ်ခငး့က
်ပနးလညးေတျ့ေတာၾကညး႕ႏိုငးပါသညး၈
<View android:id=<id>
android:layout_width=<width>
android:layout_height=<height>
>
မ္ကးပျငးံစာေပ 145
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
android:id="@+id/callButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show Dialer"
<Button android:id="@+id/callButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show Dialer" />
>
146 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<Button android:id="@+id/callButton"
android:layout_width="fill_parent"
0
android:layout_height="wrap_content"
android:text="Show Dialer" />
</LinearLayout>
android.widget.Button;
မ္ကးပျငးံစာေပ 147
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
findViewById(R.id.callButton)
(Button) findViewById(R.id.callButton)
148 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
callButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
Intent callIntent = new
Intent(Intent.CALL_ACTION,Uri.parse("tel:5551212"));
callIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH );
startActivity(callIntent);
}
});
package android_programmers_guide.AndroidPhoneDialer;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.content.Intent;
import android.net.Uri;
ထို႕ေနာကး Project ကို Compile ်ပဳလုပး၍ Emulator အတျငး့တျငး Run ၾကညး႕ပါ၈ main Activity မြ
Show Dialer ဟုအမညးရသညး႕ Button တစးခုကိုေဖား်ပေပ့ေနမညး်ဖစးသညး၈ ထို Button ကိုႏိြပးလိုကး
ေသာအခါ Call Activity ပျငးံလာမညး်ဖစးၿပီ့ 555-1212 ကို Dial ်ပဳလုပးေနပါလိမးံမညး၈ အဆိုပါလုပးေဆာင
ခ္ကးမ္ာ့ကို်ပသထာ့ပဵုကိုေအာကးတျငးေတျ႕ႏိုငးပါသညး၈
150 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 151
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<TextView android:id="@+id/textLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter Number to Dial:"
/>
<EditText android:id="@+id/phoneNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
အဆိုပါ .java ဖိုငးတျငး ဦ့စျာထညး႕သျငး့ရမညး႕ Code မ္ာ့မြာ package definition မ္ာ့်ဖစးပါသညး၈ Uri၇
Button၇ ႏြငးံ Intent မ္ာ့အတျကးသာမက EditText အတျကးကိုသာ package မ္ာ့ထညး႕သျငး့ရနး လိုအပး
ပါသညး၈ ထညး႕သျငး့ရမညး႕ package မ္ာ့ကိုေအာကးတျငးေတျ႕်မငးႏိုငးပါသညး၈
import android.widget.Button;
import android.content.Intent;
import android.net.Uri;
import android.widget.EditText;
မ္ကးပျငးံစာေပ 153
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Intent(Intent.CALL_ACTION,Uri.parse("tel:5551212"));
Intent(Intent.CALL_ACTION,Uri.parse("tel:" + phoneNumber.getText()));
package android_programmers_guide.AndroidPhoneDialer;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.content.Intent;
import android.net.Uri;
import android.widget.EditText;
154 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main );
final EditText phoneNumber = (EditText) findViewById(R.id.phoneNumber
);
final Button callButton = (Button) findViewById(R.id.callButton);
callButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
Intent CallIntent = new
Intent(Intent.CALL_ACTION,Uri.parse("tel:" + phoneNumber.getText()));
CallIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH );
startActivity(CallIntent);
}
});
}
}
မ္ကးပျငးံစာေပ 155
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
ေလံလာခဲံရေသာ Project တျငး Input သညး EditText View သို႕မညးသညး႕ အမ္ိဳ့အစာ့ Value ကိုမဆို
လကးခဵေစသညးကိုေတျ႕ရပါလိမးံမညး၈ (ဖုနး့နဵပါတးအတျကး ဂဏနး့ရိုကးထညး႕်ခငး့မဟုတးဘဲ စာသာ့မ္ာ့
ရိုကးထညး႕သညး႕အခါတျငးလညး့ လကးခဵ်ခငး့ကိုဆိုလိုပါသညး) ၁ငး့သညးထိုကဲံသို႕ Option ရိုကးထညး႕ရ
ေသာ အမ္ိဳ့အစာ့မဟုတးပါ၈ ထို႕ေၾကာငးံ Research အနညး့ငယး်ပဳလုပးကာ EditText အတျကး
Validation (ဂဏနး့၇ စာသာ့စသညး႕ Input ၏ Value ကိုစစးေဆ့်ခငး့) အခ္ိဳ႕ကိုထပးမဵေပါငး့ထညး႕ၾကညး႕
ရနးအတျကး ေအာကးပါ Parameter မ္ာ့အသဵု့်ပဳ၍ Project ကို်ပငးဆငးႏိုငးပါသညး၈
main.xml
</LinearLayout>
AndroidPhoneDialer.java
package android_programmers_guide.AndroidPhoneDialer;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.content.Intent;
import android.net.Uri;
import android.widget.EditText;
import java.util.regex.*;
public class AndroidPhoneDialer extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main );
final EditText phoneNumber = (EditText)
findViewById(R.id.phoneNumber );
final Button callButton = (Button) findViewById(R.id.callButton);
callButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
if (validatePhoneNumber(phoneNumber.getText().toString())){
Intent CallIntent = new
Intent(Intent.CALL_ACTION,Uri.parse("tel:" + phoneNumber.getText()));
CallIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH );
startActivity(CallIntent);
}
else{
showAlert("Please enter a phone number in the X-XXX-XXX-XXXX
format.",0, "Format Error", "Re-enter Number",false);
}
}
});
}
public boolean validatePhoneNumber(String number){
Pattern phoneNumber = Pattern.compile("(\\d-)?(\\d{3}-)?\\d{3}
\\d{4}");
Matcher matcher = phoneNumber.matcher(number);
return matcher.matches();
}
}
မ္ကးပျငးံစာေပ 157
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
158 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 8
Lists, Menus, and Other Views
မ္ကးပျငးံစာေပ 159
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
160 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 161
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
162 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ေပၚလာေသာ New File Dialogbox မြ File Name Text box တျငး test.xml ဟုအမညးေပ့ရပါမညး၈
ေအာကးပဵုတျငးေဖား်ပထာ့ပါသညး၈
မ္ကးပျငးံစာေပ 163
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
164 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
package testPackage.test;
import android.app.Activity;
import android.os.Bundle;
public class test extends Activity {
/** Called when the Activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.test);
/** This is our Test Activity
All code goes below */
}
}
setContentView(R.layout.test);
မ္ကးပျငးံစာေပ 165
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
package="android_programmers_guide.AndroidViews">
<application android:icon="@drawable/icon">
<activity android:name=".AndroidViews" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AutoComplete" android:label="AutoComplete">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
166 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ယခုအခါ Activity သညး Test Activity အတျကး Intent Call မ္ာ့ကို Handle ်ပဳလုပးႏိုငးသျာ့ၿပီ်ဖစးသညး၈
Test Activity သို႕ Intent Call တစးခု်ပဳလုပးရနး အခနး့ (၄)တျငးအသဵု့်ပဳခဲံေသာ Structure တစးခု်ဖငးံ
အလျနးနီ့စပးေသာ Structure တစးခုကိုအသဵု့်ပဳရပါမညး၈ ေအာကးတျငးေဖား်ပထာ့ေသာ Code သညး
Intent ကို Setup ်ပဳလုပးမညး်ဖစးပါသညး၈
startActivity(autocomplete);
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.content.Intent;
public class AndroidViews extends Activity {
/** Called when the Activity is first created. /
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
မ္ကးပျငးံစာေပ 167
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
setContentView(R.layout.main);
/**Set up our Intent /
168 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
Import android.view.Menu;
မ္ကးပျငးံစာေပ 169
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
}
AutoComplete
Button
CheckBox
EditText
RadioGroup
Spinner တို႕်ဖစးပါသညး၈
170 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
menu.add(<group>,<id>,<title>)
menu.add(0, 0, "AutoComplete");
menu.add(0, 1, "Button");
menu.add(0, 2, "CheckBox");
menu.add(0, 3, "EditText");
menu.add(0, 4, "RadioGroup");
menu.add(0, 5, "Spinner");
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, 0, "AutoComplete");
menu.add(0, 1, "Button");
menu.add(0, 2, "CheckBox");
menu.add(0, 3, "EditText");
menu.add(0, 4, "RadioGroup");
menu.add(0, 5, "Spinner");
မ္ကးပျငးံစာေပ 171
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
return true;
}
}
Menu Item မ္ာ့သို႕ Call မ္ာ့ကို Handle ်ပဳလုပးႏိုငးေစမညး႕ Method မြာ onOptionsItemSelected()
ဟူေသာ Method ပငး်ဖစးပါသညး၈ onCreateOptionsMenu() ဟူေသာ Method ကဲံသို႕ပငး
onOptionsItemSelected() ဟူေသာ Method သညးလညး့ Menu Item တစးခုကိုေရျ့ခ္ယးေသာအခါ
တျငး သတးမြတးထာ့ေသာ Code ကို execute ်ပဳလုပးရနး Override ်ပဳလုပးေစႏိုငးေသာ Boolean method
တစးခုပငး်ဖစးပါသညး၈ အဆိုပါ Override Code ကိုေအာကးပါအတိုငး့ေတျ႕ရပါလိမံးမညး၈
172 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
@Override
public boolean onOptionsItemSelected(Menu.Item item){
}
switch (item.getId()) {
case 0:
return true;
case 1:
return true;
case 2:
return true;
case 3:
return true;
case 4:
return true;
case 5:
return true;
}
return true;
package android_programmers_guide.AndroidViews;
မ္ကးပျငးံစာေပ 173
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class AndroidViews extends Activity {
/** Called when the Activity is first created. /
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
/** Add one menu item for each View in our project */
menu.add(0, 0, "AutoComplete");
menu.add(0, 1, "Button");
menu.add(0, 2, "CheckBox");
menu.add(0, 3, "EditText");
menu.add(0, 4, "RadioGroup");
menu.add(0, 5, "Spinner");
return true;
}
/** Override onOptionsItemSelected to execute code for each
menu item */
@Override
public boolean onOptionsItemSelected(Menu.Item item){
}
/** Select statement to handle calls
to specific menu items */
switch (item.getId()) {
case 0:
return true;
case 1:
return true;
case 2:
return true;
case 3:
return true;
case 4:
return true;
case 5:
return true;
}
return true;
}
}
မ္ကးပျငးံစာေပ 175
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<AutoCompleteTextView android:id="@+id/testAutoComplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button android:id="@+id/autoCompleteButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Layout"/>
<Button android:id="@+id/textColorButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Text Color"/>
176 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
android:layout_height="wrap_content"
android:text="Change Text Color"/>
</LinearLayout>
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.graphics.Color;
မ္ကးပျငးံစာေပ 177
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
အဆိုပါ Class သညး Activity ၏ အ်ခာ့ေသာ Building မ္ာ့ကိုစတငးရနးအတျကး အေ်ခခဵ Class တစးခု
်ဖစးပါသညး၈ ေဖား်ပပါ Activity ၏ အာ့လဵု့ေသာ Function မ္ာ့ကို ယခု Class အတျငး့တျငးထညး႕သျငး့
မညး်ဖစးပါသညး၈ ထို႕ေနာကး autocomplete.xml ၏ Layout ကို Load လုပးေပ့ရနးလိုအပးပါမညး၈
setContentView(R.layout.autocomplete);
178 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
changeButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
changeOption(textView);
}
});
final Button changeButton2 = (Button)
findViewById(R.id.textColorButton);
changeButton2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
changeOption2(textView);
}
});
မ္ကးပျငးံစာေပ 179
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
အထကးပါ Function သညး AutoCompleteTextView အတျကး Color.RED အ်ဖစး Text Color ကို
သတးမြတးေပ့ပါသညး၈ Color.RED ဟူေသာ တနးဖို့သညး android.graphics.Color ဟူေသာ package မြ
ယူငငးသဵု့စျဲထာ့်ခငး့်ဖစးပါသညး၈ ထို package ကိုအသဵု့်ပဳ၍ ႏြစးသကးရာအေရာငးကို ေ်ပာငး့လဲအသဵု့်ပဳ
ႏိုငးပါသညး၈ အနီေရာငးသိုသာ သဵု့စျဲမညး်ဖစးေသာေၾကာငးံ Color.RED ဟုအသဵု့်ပဳထာ့်ခငး့်ဖစးပါသညး၈
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.graphics.Color;
changeOption(textView);
}
});
final Button changeButton2 = (Button)
findViewById(R.id.textColorButton);
changeButton2.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v){
changeOption2(textView);
}
});
}
မ္ကးပျငးံစာေပ 181
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
</activity>
<activity android:name=".AutoComplete"
android:label="AutoComplete">
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category
android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
case 0:
showAutoComplete();
return true;
182 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Application ကို Android Emulator တျငးေမာငး့ႏြငးၾကညး႕ပါ၈ main Activity ကို Launch ်ပဳလုပးၿပီ့ေသာ
အခါ Menu Button ကို Click ႏိြပးပါ၈ Menu ေပၚလာသညးကိုေတျ႕ရပါမညး၈ AutoComplete menu Item
တျငး Click ႏိြပးပါ၈ AutoComplete Button Menu Item တျငး Click ႏိြပး်ခငး့်ဖငးံ autocomplete activity
ကိုအလုပးလုပးေဆာငးေၾကာငး့ ေအာကးပါပဵုအတိုငး့ေတျ႕ရပါလိမးံမညး၈
မ္ကးပျငးံစာေပ 183
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
184 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Button
ေအာကးတျငးေဖား်ပထာ့ေသာ Code မ္ာ့ကိုေလံလာၾကညး႕ပါ၈ အဆိုပါ Code မ္ာ့သညး ဖိုငးေလ့ဖိုငးတျငး
အသဵု့်ပဳရမညး႕ Code မ္ာ့်ဖစးသညး၈ ထိုဖိုငးေလ့ဖိုငးမြာ AndroidManifest.xml၇ Button.xml၇ test
Button.java ႏြငးံ AndroidViews.java ဖိုငးမ္ာ့တျငးအသဵု့်ပဳရမညး႕ Code မ္ာ့်ဖစးပါသညး၈ ယခငးအပိုငး့
တျငး်ပဳလုပးထာ့ၿပီ့်ဖစးသညး႕ AndroidViews Activity ဟူေသာ Project တျငးအဆိုပါ Code မ္ာ့ကို
ထညး႕သျငး့ရမညး်ဖစးပါသညး၈
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="android_programmers_guide.AndroidViews"
<application android:icon="@drawable/icon">
<activity android:name=".AndroidViews"
android:label="@string/app_name">
မ္ကးပျငးံစာေပ 185
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AutoComplete" android:label="AutoComplete">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testButton" android:label="TestButton">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Button.xml
testButton.java
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.graphics.Color;
public class testButton extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
186 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
setContentView(R.layout.Button);
});
}
public void changeOption(Button Button){
if (Button.getHeight()==100){
Button.setHeight(30);
}
else{
Button.setHeight(100);
}
}
public void changeOption2(Button Button){
Button.setTextColor(Color.RED);
}
}
AndroidViews.java
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.content.Intent;
}
@Override
public boolean onOptionsItemSelected(Menu.Item item){
switch (item.getId()) {
case 0:
showAutoComplete();
return true;
case 1:
showButton();
return true;
case 2:
return true;
case 3:
return true;
case 4:
return true;
case 5:
return true;
}
return true;
}
public void showButton() {
Intent showButton = new Intent(this, testButton.class);
startActivity(showButton);
}
public void showAutoComplete(){
Intent autocomplete = new Intent(this, AutoComplete.class);
startActivity(autocomplete);
}
}
188 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 189
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
CheckBox
ယခုအပိုငး့တျငး CheckBox View အတျကး Activityတစးခုကိုတညးေဆာကးပါမညး၈ Activity တညးေဆာကး
ရနးအတျကး်ပဳလုပးရမညး႕အဆငးံမ္ာ့ကိုယခငးအပိုငး့မ္ာ့တျငးေဖား်ပထာ့ၿပီ့်ဖစးပါသညး၈ထို႕ေၾကာငးံ Android
Manifest.xml ဖိုငး၇ checkbox.xml ဖိုငးႏြငးံ testCheckBox.java ဖိုငးတျငးေရ့သာ့ရမညး႕ Code မ္ာ့
ကိုသာေဖား်ပေပ့ေတာံမညး်ဖစးပါသညး၈ ထိုဖိုငးမ္ာ့သညး ယခုအပိုငး့တျငးလိုအပးမညး႕ဖိုငးမ္ာ့လညး့ ်ဖစးပါ
သညး၈ယခုအပိုငး့အတျကး အသဵု့်ပဳမညး႕ AndroidView ၏ AndroidManifest.xml ဖိုငးအတျကး
လိုအပးေသာ Code အ်ပညး႕အစဵုကုိေအာကးတျငးေဖား်ပထာ့ပါသညး၈ Eclipse ကိုအသဵု့်ပဳခဲံ်ခငး့်ဖစးပါက
လကးရိြ လုပးဆာငးေနေသာ Project မြ AndroidManifest.xml ဖိုငးမြ Code မ္ာ့ကို
ေအာကးတျငးေဖား်ပထာ့ေသာ Code မ္ာ့်ဖစးလာေစရနး ်ပငးဆငးေပ့ရပါမညး၈
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="android_programmers_guide.AndroidViews">
<application android:icon="@drawable/icon">
<activity android:name=".AndroidViews" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
190 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
</activity>
<activity android:name=".AutoComplete" android:label="AutoComplete">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".testButton" android:label="TestButton">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testCheckBox" android:label="TestCheckBox">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<CheckBox android:id="@+id/testCheckBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is the test CheckBox"/>
<Button android:id="@+id/layoutButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Layout"/>
<Button android:id="@+id/textColorButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Text Color"/>
</LinearLayout>
မ္ကးပျငးံစာေပ 191
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
testCheckBox.java
ယခု Section တျငး CheckBox Activity အတျကးလိုအပးေသာ ဖိုငးတစးဖိုငးကိုထပးမဵေဖား်ပပါမညး၈ .java
ဖိုငးအသစးတစးဖိုငးကို Project အတျငး့တျငးတညးေဆာကး၍ testCheckBox.java ဟုအမညးေပ့ပါ၈
ေအာကးတျငးေဖား်ပထာ့ေသာ Code မ္ာ့ကို testCheckBox.java ဖိုငးတျငးထညး႕သျငး့ေပ့ရပါမညး၈
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Button;
import android.graphics.Color;
AndroidViews.java
ယခု Activity ကိုတညးေဆာကး်ခငး့၏ ေနာကးဆဵု့အဆငးံမြာ AndroidViews.java ဖိုငးကို ်ပငးဆငးရနး
်ဖစးပါသညး၈ main AndroidViews ဟူေသာ Activity မြ testCheckBox Activity ကိုေခၚယူလိုေသာအခါ
192 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.content.Intent;
menu.add(0, 0, "AutoComplete");
menu.add(0, 1, "Button");
menu.add(0, 2, "CheckBox");
menu.add(0, 3, "EditText");
menu.add(0, 4, "RadioGroup");
menu.add(0, 5, "Spinner");
return true;
}
@Override
public boolean onOptionsItemSelected(Menu.Item item){
switch (item.getId()) {
case 0:
showAutoComplete();
return true;
case 1:
showButton();
return true;
case 2:
showCheckBox()
return true;
case 3:
return true;
case 4:
return true;
case 5:
return true;
}
return true;
}
မ္ကးပျငးံစာေပ 193
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
194 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
EditText
ယခုအပိုငး့တျငး ယခငး်ပဳလုပးခဲံရသကဲံသို႕ပငး EditText ဟူေသာ View အတျကး Activity တစးခုဖနးတီ့ၾက
မညး်ဖစးပါသညး၈ Activity ဖနးတီ့ႏုိငးေစမညး႕နညး့လမး့မ္ာ့ကို ယခငးအပိင
ု း့မ္ာ့တျငးေလံလာခဲံရၿပီ့်ဖစ
ေသာေၾကာငးံ Code မ္ာ့ကိုသာေဖား်ပေပ့ေတာံမညး်ဖစးပါသညး၈ main Activity ဖိုငးသဵု့ဖုိငးရိြၿပီ့ ၁ငး့တို႕မြာ
AndroidManifest.xml၇ edittext.xml ဖိုငးႏြငးံ testEditText.java ဖိုငးတို႕်ဖစးပါသညး၈ ထိုဖိုငးအတျငး့တျငး
ပါွငးမညး႕ Code မ္ာ့ကိုေအာကးတျငးေဖား်ပထာ့ပါသညး၈
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="android_programmers_guide.AndroidViews">
<application android:icon="@drawable/icon">
<activity android:name=".AndroidViews"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AutoComplete" android:label="AutoComplete">
<intent-filter>
မ္ကးပျငးံစာေပ 195
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText android:id="@+id/testEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:id="@+id/layoutButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Layout"/>
<Button android:id="@+id/textColorButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Text Color"/>
</LinearLayout>
196 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
testEditText.java
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.graphics.Color;
မ္ကးပျငးံစာေပ 197
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
AndroidViews.java
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.content.Intent;
menu.add(0, 0, "AutoComplete");
menu.add(0, 1, "Button");
menu.add(0, 2, "CheckBox");
menu.add(0, 3, "EditText");
menu.add(0, 4, "RadioGroup");
menu.add(0, 5, "Spinner");
return true;
}
@Override
public boolean onOptionsItemSelected(Menu.Item item){
switch (item.getId()) {
case 0:
showAutoComplete();
return true;
case 1:
showButton();
return true;
case 2:
showCheckBox();
return true;
case 3:
showEditText();
return true;
198 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
case 4:
showRadioGroup();
return true;
case 5:
showSpinner();
return true;
}
return true;
}
public void showButton() {
Intent showButton = new Intent(this, testButton.class);
startActivity(showButton);
}
public void showAutoComplete(){
Intent autocomplete = new Intent(this, AutoComplete.class);
startActivity(autocomplete);
}
public void showCheckBox(){
Intent checkbox = new Intent(this, testCheckBox.class);
startActivity(checkbox);
}
public void showEditText() {
Intent edittext = new Intent(this, testEditText.class);
startActivity(edittext);
}
}
မ္ကးပျငးံစာေပ 199
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
RadioGroup
ယခုအပိုငး့တျငး RadioGroup View အတျကး Activity တစးခုကိုတညးေဆာကးၾကညး႕ၾကပါမညး၈ Activity
တညးေဆာကးရနးနညး့လမး့မြာ ယခငးအသဵု့်ပဳခဲံေသာ နညး့လမး့မ္ာ့အတိုငး့ပငး်ဖစးပါသညး၈ ထို႕ေၾကာငးံ
အဓိက Activity ဖိုငးသဵု့ဖိုငး်ဖစးသညး႕ AndroidManifest.xml ဖိုငး၇ radiogroup.xml ဖိုငႏ
း ြငးံ testRadio
Group.java ဖိုငး၏ Code မ္ာ့ကိုေအာကးတျငးေဖား်ပထာ့ပါသညး၈
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="android_programmers_guide.AndroidViews">
<application android:icon="@drawable/icon">
<activity android:name=".AndroidViews"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
200 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
radiogroup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioGroup android:id="@+id/testRadioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioButton
android:text="Radio 1"
android:id="@+id/radio1"
/>
မ္ကးပျငးံစာေပ 201
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<RadioButton
android:text="Radio 2"
android:id="@+id/radio2" />
</RadioGroup>
<Button android:id="@+id/enableButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set isEnabled"/>
<Button android:id="@+id/backgroundColorButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Background Color"/>
</LinearLayout>
testRadioGroup.java
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.Button;
import android.graphics.Color;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.radiogroup);
202 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
if (radiogroup.isEnabled()){
radiogroup.setEnabled(false);
}
else{
radiogroup.setEnabled(true);
} }
public void changeOption2(RadioGroup radiogroup){
radiogroup.setBackgroundColor(Color.RED);
}
}
AndroidViews.java
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.content.Intent;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, 0, "AutoComplete");
menu.add(0, 1, "Button");
menu.add(0, 2, "CheckBox");
menu.add(0, 3, "EditText");
menu.add(0, 4, "RadioGroup");
menu.add(0, 5, "Spinner");
return true;
}
@Override
public boolean onOptionsItemSelected(Menu.Item item){
switch (item.getId()) {
case 0:
showAutoComplete();
return true;
case 1:
showButton();
မ္ကးပျငးံစာေပ 203
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
return true;
case 2:
showCheckBox();
return true;
case 3:
showEditText();
return true;
case 4:
showRadioGroup();
return true;
case 5:
showSpinner();
return true;
}
return true;
}
public void showButton() {
Intent showButton = new Intent(this, testButton.class);
startActivity(showButton);
}
public void showAutoComplete(){
Intent autocomplete = new Intent(this, AutoComplete.class);
startActivity(autocomplete);
}
public void showCheckBox(){
Intent checkbox = new Intent(this, testCheckBox.class);
startActivity(checkbox);
}
public void showEditText() {
204 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 205
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Spinner
ယခုအပိုငး့တျငး Spinner View အတျကး Activity တစးခုကိုတညးေဆာကးၾကညး႕ၾကပါမညး၈ Spinner View
ဆိုသညးမြာအ်ခာ့ေသာ Programming Language မ္ာ့တျငးအသဵု့်ပဳေသာ ComboBox ်ဖငးံဆငးတူပါ
သညး၈ Activity လုပးေဆာငးနညး့မ္ာ့ကိုေအာကးတျငးေဖား်ပထာ့ၿပီ့်ဖစးသ်ဖငးံ ေအာငး်မငးစျာလုပးေဆာင
ႏိုငးမညးဟုယူဆပါသညး၈ ထို႕ေၾကာငးံ လိုအပးေသာ ဖိုငးမ္ာ့်ဖစးေသာ AndroidManifest.xml ဖိုငး၇
spinner.xml ဖိုငးႏြငးံ testSpinner.java ဖိုငးမ္ာ့မြ လိုအပးေသာ Code မ္ာ့ကိုသာေဖား်ပေပ့ေတာံမညး
်ဖစးပါသညး၈
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="android_programmers_guide.AndroidViews">
<application android:icon="@drawable/icon">
<activity android:name=".AndroidViews"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AutoComplete" android:label="AutoComplete">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testButton" android:label="TestButton">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testCheckBox" android:label="TestCheckBox">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testEditText" android:label="TestEditText">
206 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testRadioGroup" android:label="Test
RadioGroup">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testSpinner" android:label="Test Spinner">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Spinner android:id="@+id/testSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:id="@+id/enableButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set isEnabled"/>
<Button android:id="@+id/backgroundColorButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Background Color"/>
</LinearLayout>
မ္ကးပျငးံစာေပ 207
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
testSpinner.java
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Button;
import android.graphics.Color;
208 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
spinner.setEnabled(true);
}
}
public void changeOption2(Spinner spinner){
spinner.setBackgroundColor(Color.RED);
}
}
AndroidViews.java
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.content.Intent;
public class AndroidViews extends Activity {
/** Called when the Activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, 0, "AutoComplete");
menu.add(0, 1, "Button");
menu.add(0, 2, "CheckBox");
menu.add(0, 3, "EditText");
menu.add(0, 4, "RadioGroup");
menu.add(0, 5, "Spinner");
return true;
}
@Override
public boolean onOptionsItemSelected(Menu.Item item){
switch (item.getId()) {
case 0:
showAutoComplete();
return true;
case 1:
showButton();
return true;
မ္ကးပျငးံစာေပ 209
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
case 2:
showCheckBox();
return true;
case 3:
showEditText();
return true;
case 4:
showRadioGroup();
return true;
case 5:
showSpinner();
return true;
}
return true;
}
public void showButton() {
Intent showButton = new Intent(this, testButton.class);
startActivity(showButton);
}
public void showAutoComplete(){
Intent autocomplete = new Intent(this, AutoComplete.class);
startActivity(autocomplete);
}
public void showCheckBox(){
Intent checkbox = new Intent(this, testCheckBox.class);
startActivity(checkbox);
}
public void showEditText() {
Intent edittext = new Intent(this, testEditText.class);
startActivity(edittext);
}
public void showRadioGroup(){
Intent radiogroup = new Intent(this, testRadioGroup.class);
startActivity(radiogroup);
}
public void showSpinner(){
Intent spinner = new Intent(this, testSpinner.class);
startActivity(spinner);
}
}
ထို႕ေနာကး Application ကို Launch ်ပဳလုပး၍ Menu မြ Spinner Option ကိုေရျ့ခ္ယးၾကညး႕ပါ၈ ေအာကး
ေဖား်ပပါပဵုအတိုငး့ Spinner Activity ကိုေတျ႕ရိြရပါလိမးံမညး၈
210 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 211
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Try This
212 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 9
Using the Cell Phone’s GPS
Functionality
မ္ကးပျငးံစာေပ 213
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
kml
nmea
track တို႕်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 215
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
သတိ်ပဳရနး၈ အကယး၍ စာဖတးသူမ္ာ့တျငး Google Earth မရိြေသ့ပါက Google မြအခမဲံ Download ်ပဳ
လုပးရယူႏိုငးပါသညး၈ အကယး၍ Android Location Based API Activity မ္ာ့ကို Develop ်ပဳလုပးရနး
စဥး့စာ့ထာ့ပါက Google Earth ကို Install ်ပဳလုပးထာ့်ခငး့်ဖငးံ အခ္ိနးကုနးသကးသာေစႏိုငးပါသညး၈
ထို႕ေနာကး File Menu မြ > Save As ထို႕မြ Choose KML ကိုေရျ့ခ္ယးပါ၈ ယခု ဥပမာတျငး Tampa, Flora
ေဒသကိုအေ်ခ်ပဳသညး႕ .kml ဖိုငးတစးဖိုငးကို တညးေဆာကးမညး်ဖစးပါသညး၈ ထိုအခါ ရရိြလာေသာ .kml
216 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<styleUrl>#default+nicon=http://maps.google.com/mapfiles/kml/pal3/
icon60.png+hicon=http://maps.google.com/mapfiles/kml/pal3/icon52.png</styleUrl>
<Point>
<coordinates>-82.451142,27.98146,0</coordinates>
</Point>
မ္ကးပျငးံစာေပ 217
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
</Placemark>
</Document>
</kml>
218 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ထို႕ေနာကး C:\Android ဟူေသာ Folder ကိုဖျငးံလိုကးေသာအခါတျငး adb pull ဟူေသာ Tool မြ ရယူ
ေပ့ထာ့ေသာ nmea ဖိုငးကို်မငးေတျ႕ရေစမညး်ဖစးပါသညး၈ ေအာကးေဖား်ပပါပဵုတျငး ေဖား်ပေပ့ထာ့ပါသညး၈
မ္ကးပျငးံစာေပ 219
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
(ေအာကးတင
ျ းေဖား်ပထာ့ေသာ ပဵုမ္ာ့သညး Fedora Linux ကိုအသဵု့်ပဳ၍ ရရိြထာ့ေသာပဵုမ္ာ့်ဖစးပါသညး)
220 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ထို႕ေနာကး adb pull ဟူေသာ Command ကိုအသဵု့်ပဳ၍ Android Folder အတျငး့သုိ႕ nmea ဖိုငးကို
ထညး႕သျငး့ေပ့ရပါမညး၈
Linux ႏြငးံ Windows သညး Directory Structure မတူေသာေၾကာငးံ Command ပဵုစဵလညး့ အနညး့ငယး
ကျာ်ခာ့မႈရိြမညး်ဖစးပါသညး၈
ထို႕ေနာကး ls ဟူေသာ Command ကိုအသဵု့်ပဳ၍ Android Folder အတျငး့မြ ဖိုငးမ္ာ့ကို List လုပးေခၚယူ
ၾကညး႕ရပါမညး၈ ထိုအခါ ေအာကးပါပဵုအတိုငး့ ်မငးေတျ႕ရမညး်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 221
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
ထို႕ေနာကး အဆိုပါ nmea ဖိုငးကို Fedora GUI အတျငး့ဖျငးံၾကညး႕ၿပီ့ System Text Editor ကိုအသဵု့်ပဳ ၍
အဆိုပါ ဖိုငးကိုဖျငးံၾကညး႕ထာ့ပဵုကိုေအာကးတျငးေတျ႕်မငးႏိုငးပါသညး၈
222 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ယခုအခါတျငး အဆိုပါ nmea ဖိုငးကို စစးေဆ့ၿပီ့ GPS device တျငး နညး့လမး့အမ္ိဳ့မ္ိဳ့်ဖငးံ Simulate ်ပဳ
လုပး်ခငး့တို႕ပါ ေဖား်ပခဲံၿပီ့်ဖစးေသာေၾကာငးံ Android Location Based API ကိုအသဵု့်ပဳ၍ အလုပးလုပး
ေဆာငးႏိုငးေသာ Activity တစးခုကိုတညးေဆာကးႏိုငးၿပီ်ဖစးပါသညး၈
ထို႕ေၾကာငးံ ရို့ရြငး့သညး႕ Activity တစးခုတညးေဆာကး၍ User ၏လကးရိြ GPS Location ကို ရယူၾကညး႕
ၾကမညး်ဖစးပါသညး၈ ထို႕အ်ပငး ေလာငးဂ္ီက္ဴ ႏြငးံ လဒးဂ္ီက္ဴ Coordinate အတျဲကိုလညး့ Location တစးခု
အ်ဖစး ေဖား်ပေပ့ေစႏိုငးမညး်ဖစးသညး၈ ထိုသို႕်ပဳလုပး်ခငး့်ဖငးံ Android Location-Based API ကိုေကာငး့
မျနးစျာအသဵု့်ပဳတတးသျာ့ေစမညး်ဖစးၿပီ့ ထို API ၏ function မ္ာ့ကိုသာ သိရိြနာ့လညးသျာ့ေစမညး ်ဖစး
ပါသညး၈
မ္ကးပျငးံစာေပ 223
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
224 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<uses-permission android:name="android.permission.ACCESS_GPS">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_LOCATION">
</uses-permission>
မ္ကးပျငးံစာေပ 225
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<Button
android:id="@+id/gpsButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Where Am I"
/>
226 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/latLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latitude: "
/>
မ္ကးပျငးံစာေပ 227
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<TextView
android:id="@+id/latText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/lngLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude: "
/>
<TextView
android:id="@+id/lngText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/latLabel"
228 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latitude: "
/>
<TextView
android:id="@+id/latText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/lngLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude: "
/>
<TextView
android:id="@+id/lngText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
import android.view.View;
import android.widget.TextView;
import android.content.Context;
import android.widget.Button;
import android.location.LocationManager;
မ္ကးပျငးံစာေပ 229
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
LocationManager myManager =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);
230 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
latText.setText(latPoint.toString());
lngText.setText(lngPoint.toString());
package android_programmers_guide.AndroidLBS;
import android.app.Activity;
import android.os.Bundle;
import android.location.LocationManager;
import android.view.View;
import android.widget.TextView;
import android.content.Context;
import android.widget.Button;
gpsButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
LoadCoords();
}});
}
latText.setText(latPoint.toString());
lngText.setText(lngPoint.toString());
}
}
မ္ကးပျငးံစာေပ 231
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
232 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<view class="com.google.android.maps.MapView"
android:id="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
မ္ကးပျငးံစာေပ 233
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<TextView
android:id="@+id/lngLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude: "
/>
<TextView
android:id="@+id/lngText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<view class="com.google.android.maps.MapView"
android:id="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;
import com.google.android.maps.MapController;
Point package ကို map coordinate မ္ာ့ပါွငးေသာ point value မ္ာ့အ်ဖစး အသဵု့်ပဳရပါလိမးံမညး၈
အဆိုပါ map coordinate မ္ာ့သညး လကးရိြတညးေနရာ point ကို map ၏ အလယးဗဟို Center သို႕
ေ်ပာငး့ေရႊ႕ေပ့ရနးအသဵု့်ပဳပါသညး၈ အဆိုပါ package ႏြစးခုသညး MapView ကိုအသဵု့်ပဳရနးအတျကး မရိြ
မ်ဖစး package မ္ာ့်ဖစးပါသညး၈
234 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ထို႕ေနာကး map ကို establish ်ပဳလုပးရနးႏြငးံ Coordinate မ္ာ့ကို Pass ်ပဳလုပးႏိုငးမညး႕ Code မ္ာ့ကို
ထညး႕သျငး့ရနးအဆငးံသငးံ်ဖစးေနၿပီ်ဖစးသညး၈ ထို႕ေၾကာငးံေရြ့သီ့စျာ MapView တစးခုကို setup ်ပဳလုပး၍
main.xml ႏြငးံ assign ်ပဳလုပးေပ့ရပါလိမးံမညး၈ ထို႕ေနာကး Point တစးခုကို setup ်ပဳလုပးၿပီ့ အဆိုပါ
point တျငး GPS မြ ရယူထာ့ေသာ latPoint ႏြငးံ IngPoint တနးဖို့မ္ာ့ကို assign ်ပဳလုပးေပ့ရပါမညး၈
ထို႕ေနာကး map ကို establish ်ပဳလုပးရနးႏြငးံ Coordinate မ္ာ့ကို Pass ်ပဳလုပးႏိုငးမညး႕ Code မ္ာ့ကို
ထညး႕သျငး့ရနးအဆငးံသငးံ်ဖစးေနၿပီ်ဖစးသညး၈ ထို႕ေၾကာငးံေရြ့သီ့စျာ MapView တစးခုကို setup ်ပဳလုပး၍
main.xml ႏြငးံ assign ်ပဳလုပးေပ့ရပါလိမးံမညး၈ ထို႕ေနာကး Point တစးခုကို setup ်ပဳလုပးၿပီ့ အဆိုပါ
point တျငး GPS မြ ရယူထာ့ေသာ latPoint ႏြငးံ IngPoint တနးဖို့မ္ာ့ကို assign ်ပဳလုပးေပ့ရပါမညး၈
ထို႕ေနာကး Google Map မြ Location တစးခုအတျကး သတးမြတးထာ့ေသာ Point တစးခုကို Focus ်ပဳလုပး
ေစႏိုငးမညး႕ MapControllerကုိတညးေဆာကးႏိုငးၿပီ်ဖစးသညး၈ ထို႕ေၾကာငးံ getController() ဟူေသာ
method ကို အသဵု့်ပဳ၍ MapView မြ သတးမြတးထာ့ေသာ Map တျငး Controller တစးခုကို Establish
်ပဳလုပးရပါမညး၈
ထို႕ေနာကး Google Map မြ Location တစးခုအတျကး သတးမြတးထာ့ေသာ Point တစးခုကို Focus ်ပဳလုပး
ေစႏိုငးမညး႕ MapControllerကုိတညးေဆာကးႏိုငးၿပီ်ဖစးသညး၈ ထို႕ေၾကာငးံ getController() ဟူေသာ
method ကို အသဵု့်ပဳ၍ MapView မြ သတးမြတးထာ့ေသာ Map တျငး Controller တစးခုကို Establish
်ပဳလုပးရပါမညး၈
myMapController.centerMapTo(myLocation, false);
myMapController.zoomTo(9);
ထို႕ေနာကး Google Maps ကို utilitze ်ပဳလုပးရနး လိုအပးေသာ Code မ္ာ့ကို ေရ့သာ့ၿပီ့စီ့ၿပီ်ဖစးသညး၈
ထို႕ေၾကာငးံ Class မြ Code အ်ပညး႕အစဵုကိုေအာကးပါအတိုငး့ေတျ႕်မငးရမညး်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 235
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
package android_programmers_guide.AndroidLBS;
import android.os.Bundle;
import android.location.LocationManager;
import android.view.View;
import android.widget.TextView;
import android.content.Context;
import android.widget.Button;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;
import com.google.android.maps.MapController;
Double latPoint =
myManager.getCurrentLocation("gps").getLatitude()*1E6;
Double lngPoint =
myManager.getCurrentLocation("gps").getLongitude()*1E6;
latText.setText(latPoint.toString());
lngText.setText(lngPoint.toString());
236 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Where Am I ဟူေသာ Button ကို Click ႏိြပးႀကညး႕ပါ၈ ေပၚလာမညး႕ Output ကိုေအာကးတျငးေဖား်ပ ထာ့
သညး႕ပဵုအတိုငး့ေတျ႕်မငးရမညး်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 237
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<view class="com.google.android.maps.MapView"
android:id="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<Button android:id="@+id/buttonZoomIn"
style="?android:attr/buttonStyleSmall"
android:text="+"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/buttonZoomOut"
style="?android:attr/buttonStyleSmall"
android:text="-"
238 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
android:layout_alignBottom="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
မ္ကးပျငးံစာေပ 239
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<view class="com.google.android.maps.MapView"
android:id="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button android:id="@+id/buttonZoomIn"
style="?android:attr/buttonStyleSmall"
android:text="+"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/buttonZoomOut"
style="?android:attr/buttonStyleSmall"
android:text="-"
android:layout_alignBottom="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
ေနာကးဆဵု့အရ zoom in ႏြငးံ zoom out ဟူေသာ feature အတျကး function မ္ာ့တညးေဆာကးရပါမညး၈
အ်မငးံဆဵု့အသဵု့်ပဳႏိုငးမညး႕ Zoom In Level မြာ 21 ်ဖစးၿပီ့အနိမးံဆဵု့ Zoom Out Level မြာ 1 ဟုသတး
မြတးပါမညး၈ ထို႕ေၾကာငးံ function အတျငး့တျငး adjust မ်ပဳလုပးမီတျငး လကးရိြ level ကိုစမး့သပးၾကညး႕ၾက
ပါမညး၈ ထိုသို႕စမး့သပးမႈ်ဖငးံ မညးသညး႕ ်ပသနာမြမေပၚေစရနး ေသခ္ာေအာငး်ပဳလုပးသငးံပါသညး၈
Function မ္ာ့အတျငး့တျငး MapView ႏြငးံ MapController မ္ာ့ကို Pass လုပးေစေၾကာငး့ သတိ်ပဳပါ၈ ထိုမြ
Zoom Level ကိုသတးမြတးရနး ရို့ရြငး့ေသာ integer manipulation ကိုအသဵု့်ပဳပါသညး၈ မြတးသာ့သင
ေသာထူ့်ခာ့သညး႕အခ္ကးမ္ာ MapController သညး Zoom Value ကို ်ပဳ်ပငးေပ့ႏိုးငးမညး႕ MapView
သို႕ေရႊ႕လ္ာ့၍ ဆႏၵရိြသညး႕ Zoom Level ကိုခ္ိနးညိြသျာ့်ခငး့ပငး်ဖစးပါသညး၈ အဆိုပါ ဆကးသျယးခ္ကးက
Remote Control ႏြငးံ TV ကိုဥပမာထာ့၍ စဥး့စာ့ပါ၈ Remote Control သညး TV မြ သိမး့ဆညး့မြတးသာ့
ထာ့သညး႕ Channel 5 ကို Tune ်ပဳလုပးသျာ့ေစ်ခငး့်ဖစးၿပီ့ Remote Control မြ Channel 5 ကို်ပဳလုပး
သိမး့ဆညး့ေစ်ခငး့မဟုတးပါ၈
package android_programmers_guide.AndroidLBS;
import android.os.Bundle;
import android.location.LocationManager;
import android.view.View;
import android.widget.TextView;
import android.content.Context;
import android.widget.Button;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;
import com.google.android.maps.MapController;
မ္ကးပျငးံစာေပ 241
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Function မ္ာ့အတျငး့တျငး MapView ႏြငးံ MapController မ္ာ့ကို Pass လုပးေစေၾကာငး့ သတိ်ပဳပါ၈ ထိုမြ
Zoom Level ကိုသတးမြတးရနး ရို့ရြငး့ေသာ integer manipulation ကိုအသဵု့်ပဳပါသညး၈ မြတးသာ့သင
ေသာထူ့်ခာ့သညး႕အခ္ကးမ္ာ MapController သညး Zoom Value ကို ်ပဳ်ပငးေပ့ႏိုးငးမညး႕ MapView
သို႕ေရႊ႕လ္ာ့၍ ဆႏၵရိြသညး႕ Zoom Level ကိုခ္ိနးညိြသျာ့်ခငး့ပငး်ဖစးပါသညး၈ အဆိုပါ ဆကးသျယးခ္ကးက
Remote Control ႏြငးံ TV ကိုဥပမာထာ့၍ စဥး့စာ့ပါ၈ Remote Control သညး TV မြ သိမး့ဆညး့မြတးသာ့
242 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 243
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
244 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/gpsButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Where Am I"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/latLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latitude: "
/>
<TextView
android:id="@+id/latText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/lngLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude: "
/>
<TextView
android:id="@+id/lngText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<view class="com.google.android.maps.MapView"
android:id="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button android:id="@+id/buttonZoomIn"
style="?android:attr/buttonStyleSmall"
မ္ကးပျငးံစာေပ 245
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
android:text="+"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/buttonMapView"
style="?android:attr/buttonStyleSmall"
android:text="Map"
android:layout_alignRight="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/buttonSatView"
style="?android:attr/buttonStyleSmall"
android:text="Sat"
android:layout_alignRight="@+id/myMap"
android:layout_alignBottom="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/buttonZoomOut"
style="?android:attr/buttonStyleSmall"
android:text="-"
android:layout_alignBottom="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
AndroidLBS.java
package android_programmers_guide.AndroidLBS;
import android.os.Bundle;
import android.location.LocationManager;
import android.view.View;
import android.widget.TextView;
import android.content.Context;
import android.widget.Button;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;
import com.google.android.maps.MapController;
246 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
}});
final Button gpsButton = (Button) findViewById(R.id.gpsButton);
gpsButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
LoadProviders(myMap,myMapController);
}});
final Button viewMap = (Button) findViewById(R.id.buttonMapView);
viewMap.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
ShowMap(myMap);
}});
final Button viewSat = (Button) findViewById(R.id.buttonSatView);
viewSat.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
ShowSat(myMap);
}});
}
public void LoadProviders(MapView mv, MapController mc){
TextView latText = (TextView) findViewById(R.id.latText);
TextView lngText = (TextView) findViewById(R.id.lngText);
LocationManager myManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
Double latPoint =
myManager.getCurrentLocation("gps").getLatitude()*1E6;
Double lngPoint =
myManager.getCurrentLocation("gps").getLongitude()*1E6;
latText.setText(latPoint.toString());
lngText.setText(lngPoint.toString());
Point myLocation = new
Point(latPoint.intValue(),lngPoint.intValue());
mc.centerMapTo(myLocation, false);
mc.zoomTo(9);
}
public void ZoomIn(MapView mv, MapController mc){
if(mv.getZoomLevel()!=21){
mc.zoomTo(mv.getZoomLevel()+ 1);
}
}
public void ZoomOut(MapView mv, MapController mc){
if(mv.getZoomLevel()!=1){
mc.zoomTo(mv.getZoomLevel()- 1);
}
}
public void ShowMap(MapView mv){
if (mv.isSatellite()){
mv.toggleSatellite();
}
}
public void ShowSat(MapView mv){
if (!mv.isSatellite()){
mv.toggleSatellite();
}
}
}
248 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 10
Using the Google API with GTalk
မ္ကးပျငးံစာေပ 249
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
အခနး့ (၆) တျငးပငး Google API ၏အသဵု့်ပဳပဵုမ္ာ့ကို နိဒါနး့ပ္ိဳ့အသဵု့်ပဳခဲံၿပီ့်ဖစးပါသညး၈ Google API ႏြငးံ
Google Map မ္ာ့ကိုအသဵု့်ပဳေစမညး႕ Activity တစးခုကိုတညးေဆာကးခဲံၿပီ့်ဖစးပါသညး၈ API ၏ လျယးကူ
ၿပီ့၇ ်ပဳလျယး်ပငးလျယးရိြေသာအခ္ကးမ္ာ့ေၾကာငးံ Google Map မြအသဵု့်ပဳသူ၏ location ကိုလျယးကူလြ္င
်မနးစျာရရိြႏိုငး်ခငး့်ဖစးပါသညး၈ Code အနညး့ငယးေရ့သာ့ရဵု်ဖငးံ map ကိုမညးကဲံသုိ႕အသဵု့ခ္ႏိုငးသညး ဆို
ေသာအခ္ကးကိုပါေလံလာခဲံရပါသညး၈ Google API သညး Google Maps ၏ လုပးေဆာငးခ္ကးတစးခုထက
ပိုသညးဟူေသာအခ္ကးကို စဥး့စာ့ႏိုငးလိမးံမညးဟုထငးပါသညး၈ Google API အတျကး base package မြာ
com.google ပငး်ဖစးပါသညး၈ အေ်ခခဵအာ့်ဖငးံ Google API တျငး GTalk ၇ Google Calendar၇ Google
Docs၇ Google Spreadsheet ႏြငးံ အ်ခာ့ေသာ Google Service မ္ာ့ကဲံသို႕ေသာ လုပးေဆာငးခ္ကးမ္ာ့က
ဖနးတီ့ ေစႏိုငးေသာ package မ္ာ့ပါွငးပါသညး၈
ယခုအခနး့တျငး Android SDK ၏ GTalk package ကို အသဵု့်ပဳ၍ small Activity တစးခုကိုတညးေဆာက
ၾကညး႕ၾကပါမညး၈ ထို Activity ၿပီ့ဆဵု့ေသာအခါတျငး အသဵု့်ပဳမညး႕ဖုနး့မြ Gtalk message မ္ာ့ကို အ်ခာ့
ေသာ Gtalk အသဵု့်ပဳသူမ္ာ့ထဵသို႕ေပ့ပို႕ေစႏိုငးရဵုသာမက ထိုသူမ္ာ့မြ Message မ္ာ့ကိုလညး့ လကးခဵ
ေစႏိုငးမညး်ဖစးပါသညး၈
250 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Emulator ပျငးံလာၿပီ့ေသာအခါတျငး All Shortcut ကို Click ႏိြပးပါ၈ Dev Tools Item ကိုရြာ၍ launch ်ပဳ
လုပးပါ၈ ထိုအခါေအာကးေဖား်ပပါပဵုအတိင
ု း့ ေပၚလာသညးကိုေတျ႕ရပါမညး၈
မ္ကးပျငးံစာေပ 251
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
XMPP Settings ကိုရြာေဖျေတျ႕ရိြသညးအထိ Dev Tools Menu ကို Scroll ်ပဳလုပးရြာေဖျပါ၈ ထို႕ေနာကး
XMPP Settings တျငးေရျ့ခ္ယးေသာအခါတျငး ေအာကးတျငးေဖား်ပထာ့ေသာပဵုအတိုငး့ေပၚလာသညးက
ေတျ႕ရမညး်ဖစးပါသညး၈
XMPP Settings ကိုဖျငးံလိုကးေသာအခါ ေတျ႕ရမညး႕ Activity သညး GTalk Settings ပငး်ဖစးပါသညး၈ ၁ငး့
သညး Google API ၏ က္နးရိြေနေသာ package မ္ာ့နြငးံ အလုပးလုပးေဆာငးႏိုငးရနးအတျကး လမး့ညႊနးခ္ကး
တစးခုလညး့်ဖစးပါသညး၈
252 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Username ႏြငးံ Password ကိုထညး႕သျငး့ၿပီ့ေနာကး Sign In တျငး Click ႏိြပးပါ၈ Android Emulator တျငး
information မ္ာ့ကို Authenticate ်ပဳလုပးေနေၾကာငး့ ေအာကးေဖား်ပပါပဵုအတိုငး့ ေဖား်ပေနမညး်ဖစးပါ
သညး၈ Emulator မြ Information ကို authenticate ်ပဳလုပးေနစဥးအတျငး့တျငး Authenticating ဟူေသာ
message ကိုေဖား်ပေပ့ေနမညး်ဖစးသညး၈
မ္ကးပျငးံစာေပ 253
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
254 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
<ListView
android:id="@+id/messageList"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:scrollbars="vertical"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
အဆိုပါ ListView ကို main layout tag တျငးေနရာခ္ထာ့ေပ့ရပါမညး၈ ListView Layout ေအာကးတျငး
ေအာကးတျငးေဖား်ပထာ့သညး႕အတိုငး့ EditText တစးခုအတျကး layout ကိုေနရာခ္ထာ့ေပ့ရပါမညး၈
အဆိုပါ EditText သညး ေပ့ပို႕မညး႕သူ၏ Address အ်ဖစးအသဵု့်ပဳ၍ message ေပ့ပို႕ေစႏိုငးမညး်ဖစး
ပါသညး၈
<EditText
android:id="@+id/messageTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:minWidth="250dp"
android:scrollHorizontally="true" />
မ္ကးပျငးံစာေပ 255
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:minWidth="250dp"
android:scrollHorizontally="true" />
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Msg">
</Button>
</LinearLayout>
android:minWidth="250dp"
android:scrollHorizontally="true" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:minWidth="250dp"
android:scrollHorizontally="true" />
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Msg">
</Button>
</LinearLayout>
</LinearLayout>
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ListAdapter;
import android.widget.Button;
import com.google.android.gtalkservice.IGTalkSession;
import com.google.android.gtalkservice.IGTalkService;
import com.google.android.gtalkservice.GTalkServiceConstants;
import com.google.android.gtalkservice.IChatSession;
မ္ကးပျငးံစာေပ 257
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.provider.Im;
import android.graphics.Color;
import android.view.View;
import android.widget.SimpleCursorAdapter;
258 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
EditText messageText;
ListView messageList;
IGTalkSession myIGTalkSession;
EditText messageTo;
Button sendButton;
myIGTalkSession = null;
messageText = (EditText) findViewById(R.id.messageText);
messageList = (ListView) findViewById(R.id.messageList);
messageTo = (EditText) findViewById(R.id.messageTo);
sendButton = (Button) findViewById(R.id.btnSend);
sendButton.setOnClickListener(this);
messageList.setBackgroundColor(Color.GRAY );
this.bindService(new
Intent().setComponent(GTalkServiceConstants.GTALK_SERVICE_COMPONENT),
connection, 0);
ေအာကးပါ Code မ္ာ့သညး ပို႕လႊတးသူ (ကၽျႏုးပးတို႕) ႏြငးံ messageTo recipient အၾကာ့ database
အတျငး့တျငးရိြေသာ message မ္ာ့ကို query ်ပဳလုပးေဖား်ပေစရနး အသဵု့်ပဳပါသညး၈
260 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
try {
IChatSession chatSession;
chatSession =
myIGTalkSession.createChatSession(messageTo.getText().toString(););
chatSession.sendTextMessage(messageText.getText().toString());
} catch (DeadObjectException ex) {
myIGTalkSession = null;
}
package android_programmers_guide.GoogleAPI;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.provider.Im;
import android.graphics.Color;
import android.view.View;
မ္ကးပျငးံစာေပ 261
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ListAdapter;
import android.widget.Button;
import android.widget.SimpleCursorAdapter;
import com.google.android.gtalkservice.IGTalkSession;
import com.google.android.gtalkservice.IGTalkService;
import com.google.android.gtalkservice.GTalkServiceConstants;
import com.google.android.gtalkservice.IChatSession;
}
private ServiceConnection connection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) {
try {
myIGTalkSession =
IGTalkService.Stub.asInterface(service).getDefaultSession();
} catch (DeadObjectException e) {
myIGTalkSession = null;
}
}
public void onServiceDisconnected(ComponentName name) {
myIGTalkSession = null;
}
};
try {
IChatSession chatSession;
chatSession =
myIGTalkSession.createChatSession(messageTo.getText().toString());
262 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
chatSession.sendTextMessage(messageText.getText().toString());
} catch (DeadObjectException ex) {
myIGTalkSession = null;
}
}
}
အဆိုပါ Activity ကိုစမး့သပးရနးအတျကး ကိုယးပိုငး gmail account သို႕”Hello” ဟူ၍ Message တစးေစာငး
ေပ့ပို႕ ၾကညး႕ၾကပါမညး၈
မ္ကးပျငးံစာေပ 263
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
264 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 265
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Message List ၏ Font ကိုေ်ပာငး့လဲရနး၇ Message List အတျငး့မြ Font Color ကိုေ်ပာငး့လဲရနး၇
Message List ၏ BackGround Color ကိုေ်ပာငး့လဲရနး စသညးတို႕ကိုကိုယးတိုငးလကးေတျ႕ လုပးေဆာင
ၾကညး႕သငးံပါသညး၈
266 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 11
Application: Find a Friend
မ္ကးပျငးံစာေပ 267
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
မ္ကးပျငးံစာေပ 269
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
270 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
အတျကးယခုေနရာတျငးေအာကးတျငး်ပထာ့သညး႕ပဵုအတိုငး့android_programmers_guide.FindAFriend
ဟူေသာ Directory ကိုအသဵု့်ပဳရပါမညး၈
မ္ကးပျငးံစာေပ 271
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
# sqlite friends.db
272 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
CREATE TABLE friends (_id INTEGER PRIMARY KEY, name TEXT, location TEXT,
created INTEGER, modified INTEGER);
274 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
import android.net.Uri;
import android.provider.BaseColumns;
BaseColumns ကို main Friends Class ၏ subclass တစးခုမြ implement ်ပဳလုပးပါလိမးံမညး၈ Subclass
ကို Friend ဟုအမညးေပ့ရပါမညး၈ အဘယးေၾကာငးံဆိုေသား ၁ငး့တျငး Frined dataset မြ friend တစးဦ့
မ္ကးပျငးံစာေပ 275
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
အဆိုပါ Class တျငး Friends database ၏ Column တစးခုစီခ္ငး့စီကိုလညး့ေကာငး့၇ Content URI ႏြငးံ
Record မ္ာ့အတျကး default sort order ကိုလညး့ေကာငး့သတးမြတးေပ့ႏိုငးသညး႕ static variable
အခ္ိဳ႕ပါွငးပါသညး၈ Content URI တစးခုကို Handle ်ပဳလုပးေစမညး႕ Content ကို identify ်ပဳလုပးရနး
အသဵု့်ပဳပါသညး၈ တနးဖို့မ္ာ့သညးတစးခုႏြငးံတစးခု ထပးတူမရိြေစသညး႕ တနးဖို့မ္ာ့်ဖစးပါသညး၈ define
်ပဳလုပးရနးလိုအပးသညး႕ string မ္ာ့မြာေအာကးပါအတိုငး့်ဖစးပါသညး၈
import android.net.Uri;
import android.provider.BaseColumns;
276 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
import android_programmers_guide.FindAFriend.Friends;
import android.content.*;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import java.util.HashMap;
မ္ကးပျငးံစာေပ 277
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Content Provider တျငး onCreate()၇ query()၇ delete() ႏြငးံ update() ကဲံသို႕ေသာ ထိနး့ခ္ဳပးေစႏိုငး
မညး႕ method မ္ာ့စျာပါွငးပါသညး၈ အဘယးေၾကာငးံဆိုေသား အဆိုပါ method မ္ာ့ကို Content
Provider ကိုအသဵု့်ပဳ၍ Activity မြေခၚယူေစေသာအခါ Friends database ကိွ
ု ငးေရာကးႏိုငးေစရနး
အတျကး ၁ငး့တို႕ကို override ်ပဳလုပးထိနး့ခ္ဳပးရပါမညး၈
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE friends (_id INTEGER PRIMARY KEY,"
+ "name TEXT," + "location TEXT," + "created INTEGER,"
+ "modified INTEGER" + ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + "to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS friends");
onCreate(db);
}
}
@Override
public boolean onCreate() {
DatabaseHelper dbHelper = new DatabaseHelper();
mDB = dbHelper.openDatabase(getContext(), DATABASE_NAME, null,
DATABASE_VERSION);
return (mDB == null) ? false : true;
}
@Override
public Cursor query(Uri url, String[] projection, String selection,
String[] selectionArgs, String sort) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
switch (URL_MATCHER.match(url)) {
case FRIENDS:
qb.setTables("friends");
qb.setProjectionMap(FRIENDS_PROJECTION_MAP);
break;
case FRIENDS_ID:
qb.setTables("friends");
qb.appendWhere("_id=" + url.getPathSegments().get(1));
break;
default:
မ္ကးပျငးံစာေပ 279
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
String orderBy;
if (TextUtils.isEmpty(sort)) {
orderBy = Friends.Friend.DEFAULT_SORT_ORDER;
} else {
orderBy = sort;
}
Query() method သညး database URL မြ ၁ငး့အတျငး့ Pass ်ပဳလုပးရနးအတျကး validity ကိုစစးေဆ့
ၾကညး႕မညး်ဖစးၿပီ့ query sort order ကိုလညး့ define ်ပဳလုပးေစမညး်ဖစးပါသညး၈ URL check ဆိုသညး
မြာ Friends databse တစးခုတညး့ကို ွငးေရာကးရနးႀကိဳ့စာ့်ခငး့ကိုေသခ္ာေအာငး်ပဳလုပးေစ်ခငး့ ်ဖစးပါ
သညး၈ အကယး၍ အ်ခာ့ေသာ activity တစးခုမြ သို႕မဟုတး အ်ခာ့ေသာ Content Provider တစးခုမြ
database သို႕ွငးေရာကးရနးႀကိဳ့ပမး့သညး႕အခါတျငး query() method ကိုခ္နးလြပးထာ့ခဲံမညး်ဖစးပါသညး၈
@Override
public Uri insert(Uri url, ContentValues initialValues) {
long rowID;
ContentValues values;
if (initialValues != null) {
values = new ContentValues(initialValues);
} else {
values = new ContentValues();
}
280 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
if (URL_MATCHER.match(url) != FRIENDS) {
throw new IllegalArgumentException("Unknown URL " + url);
}
if (values.containsKey(Friends.Friend.CREATED_DATE ) == false) {
values.put(Friends.Friend.CREATED_DATE, now);
}
if (values.containsKey(Friends.Friend.MODIFIED_DATE) == false) {
values.put(Friends.Friend.MODIFIED_DATE, now);
}
if (values.containsKey(Friends.Friend.NAME) == false) {
values.put(Friends.Friend.NAME,
r.getString(android.R.string.untitled));
}
if (values.containsKey(Friends.Friend.LOCATION) == false) {
values.put(Friends.Friend.LOCATION , "");
}
@Override
public int delete(Uri url, String where, String[] whereArgs) {
int count;
long rowId = 0;
switch (URL_MATCHER.match(url)) {
case FRIENDS:
count = mDB.delete("friends", where, whereArgs);
break;
case FRIENDS_ID:
String segment = url.getPathSegments().get(1);
rowId = Long.parseLong(segment);
count = mDB
.delete("friends", "_id="
+ segment
+ (!TextUtils.isEmpty(where) ? " AND (" + where
+ ')' : ""), whereArgs);
break;
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
getContext().getContentResolver().notifyChange(url, null);
return count;
မ္ကးပျငးံစာေပ 281
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
@Override
public int update(Uri url, ContentValues values, String where, String[]
whereArgs) {
int count;
switch (URL_MATCHER.match(url)) {
case FRIENDS:
count = mDB.update("friends", values, where, whereArgs);
break;
case FRIENDS_ID:
String segment = url.getPathSegments().get(1);
count = mDB
.update("friends", values, "_id=" + segment
+ (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
break;
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
getContext().getContentResolver().notifyChange(url, null);
return count;
}
vnd.android.cursor.dir/vnd.<package>
@Override
public String getType(Uri url) {
switch (URL_MATCHER.match(url)) {
case FRIENDS:
return
"vnd.android.cursor.dir/vnd.android_programmers_guide.friend";
case FRIENDS_ID:
return
"vnd.android.cursor.item/vnd.android_programmers_guide.friend";
default:
throw new IllegalArgumentException("Unknown URL " +
url);
}
}
282 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
package android_programmers_guide.FindAFriend;
import android_programmers_guide.FindAFriend.Friends;
import android.content.*;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import java.util.HashMap;
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE friends (_id INTEGER PRIMARY KEY,"
+ "name TEXT," + "location TEXT," + "created INTEGER,"
+ "modified INTEGER" + ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + "to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS friends");
onCreate(db);
}
}
@Override
public boolean onCreate() {
DatabaseHelper dbHelper = new DatabaseHelper();
mDB = dbHelper.openDatabase(getContext(), DATABASE_NAME, null,
DATABASE_VERSION);
return (mDB == null) ? false : true;
}
မ္ကးပျငးံစာေပ 283
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
@Override
public Cursor query(Uri url, String[] projection, String selection,
String[] selectionArgs, String sort) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
switch (URL_MATCHER.match(url)) {
case FRIENDS:
qb.setTables("friends");
qb.setProjectionMap(FRIENDS_PROJECTION_MAP);
break;
case FRIENDS_ID:
qb.setTables("friends");
qb.appendWhere("_id=" + url.getPathSegments().get(1));
break;
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
String orderBy;
if (TextUtils.isEmpty(sort)) {
orderBy = Friends.Friend.DEFAULT_SORT_ORDER;
} else {
orderBy = sort;
}
@Override
public String getType(Uri url) {
switch (URL_MATCHER.match(url)) {
case FRIENDS:
return
"vnd.android.cursor.dir/vnd.android_programmers_guide.friend";
case FRIENDS_ID:
return
"vnd.android.cursor.item/vnd.android_programmers_guide.friend";
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
}
@Override
public Uri insert(Uri url, ContentValues initialValues) {
long rowID;
ContentValues values;
if (initialValues != null) {
values = new ContentValues(initialValues);
} else {
values = new ContentValues();
}
if (URL_MATCHER.match(url) != FRIENDS) {
284 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
if (values.containsKey(Friends.Friend.CREATED_DATE ) == false) {
values.put(Friends.Friend.CREATED_DATE, now);
}
if (values.containsKey(Friends.Friend.MODIFIED_DATE) == false) {
values.put(Friends.Friend.MODIFIED_DATE, now);
}
if (values.containsKey(Friends.Friend.NAME) == false) {
values.put(Friends.Friend.NAME,
r.getString(android.R.string.untitled));
}
if (values.containsKey(Friends.Friend.LOCATION) == false) {
values.put(Friends.Friend.LOCATION , "");
}
@Override
public int delete(Uri url, String where, String[] whereArgs) {
int count;
long rowId = 0;
switch (URL_MATCHER.match(url)) {
case FRIENDS:
count = mDB.delete("friends", where, whereArgs);
break;
case FRIENDS_ID:
String segment = url.getPathSegments().get(1);
rowId = Long.parseLong(segment);
count = mDB
.delete("friends", "_id="
+ segment
+ (!TextUtils.isEmpty(where) ? " AND (" + where
+ ')' : ""), whereArgs);
break;
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
getContext().getContentResolver().notifyChange(url, null);
return count;
မ္ကးပျငးံစာေပ 285
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
@Override
public int update(Uri url, ContentValues values, String where, String[]
whereArgs) {
int count;
switch (URL_MATCHER.match(url)) {
case FRIENDS:
count = mDB.update("friends", values, where, whereArgs);
break;
case FRIENDS_ID:
String segment = url.getPathSegments().get(1);
count = mDB
.update("friends", values, "_id=" + segment
+ (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
break;
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
getContext().getContentResolver().notifyChange(url, null);
return count;
}
static {
URL_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
URL_MATCHER.addURI("android_programmers_guide.FindAFriend.Friends",
"friend", FRIENDS);
URL_MATCHER.addURI("android_programmers_guide.FindAFriend.Friends",
"friend/#", FRIENDS_ID);
FRIENDS_PROJECTION_MAP = new HashMap<String, String>();
FRIENDS_PROJECTION_MAP.put(Friends.Friend._ID, "_id");
FRIENDS_PROJECTION_MAP.put(Friends.Friend.NAME, "name");
FRIENDS_PROJECTION_MAP.put(Friends.Friend.LOCATION, "location");
FRIENDS_PROJECTION_MAP.put(Friends.Friend.CREATED_DATE, "created");
FRIENDS_PROJECTION_MAP.put(Friends.Friend.MODIFIED_DATE,
"modified");
}
}
286 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Editing AndroidManifest.xml
ေအာကးတျငးေဖား်ပထာ့ေသာ Code မ္ာ့သညး FindAFriend project အတျကး အသဵု့်ပဳရမညး႕ Android
Manifest.xml ဖိုငး၏ Code မ္ာ့်ဖစးပါသညး၈ ထို Code တျငး Activity အသစးမ္ာ့အတျကး လိုအပးေသာ
Intent Filter အမ္ာ့အ်ပာ့ကို ေပါငး့ထညး႕ရပါမညး၈ ထို Intent Filter မ္ာ့သညး Friend ၏ Location ကို
်ပငးဆငးရနး၇ Friedn ၏ အမညးကို်ပငးဆငးရနးႏြငးံ Google Map တို႕ကို launch ်ပဳလုပးရနးတ႕ို အတျကး
်ဖစးပါသညး၈
မ္ကးပျငးံစာေပ 287
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
android:authorities="android_programmers_guide.FindAFriend.Friends" />
<activity android:name=".FindAFriend"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<dataandroid:mimeType="vnd.android.cursor.dir/
vnd.android_programmers_guide.friend" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<dataandroid:mimeType="vnd.android.cursor.item/
vnd.android_programmers_guide.friend" />
</intent-filter>
</activity>
<activity android:name=".FriendsMap" android:label="FriendsMap">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity android:name="LocationEditor"
android:label="@string/title_note">
<intent-filter android:label="@string/resolve_edit">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action
android:name="com.google.android.notepad.action.EDIT_LOCATION" />
<category android:name="android.intent.category.DEFAULT" />
<dataandroid:mimeType="vnd.android.cursor.item/
vnd.android_programmers_guide.friend" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT" />
<dataandroid:mimeType="vnd.android.cursor.dir/
vnd.android_programmers_guide.friend" />
</intent-filter>
</activity>
<activity android:name="NameEditor"
android:label="@string/title_edit_title"
android:theme="@android:style/Theme.Dialog">
<intent-filter android:label="@string/resolve_title">
<action
288 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
android:name="com.google.android.notepad.action.EDIT_NAME"
/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
<dataandroid:mimeType="vnd.android.cursor.item/
vnd.android_programmers_guide.friend" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_GPS">
</uses-permission><uses-permission
android:name="android.permission.ACCESS_LOCATION">
</uses-permission></manifest>
မ္ကးပျငးံစာေပ 289
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingBottom="3dip">
<EditText android:id="@+id/name"
android:maxLines="1"
android:layout_marginTop="2dip"
android:layout_width="wrap_content"
android:ems="25"
android:layout_height="wrap_content"
android:autoText="true"
android:capitalize="sentences"
android:scrollHorizontally="true" />
<Button android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/button_ok" />
</LinearLayout>
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
290 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Cursor mCursor;
EditText mText;
}
setContentView(R.layout.name_editor);
ယခငးေဖား်ပခဲံေသာ နမူနာ Code တျငး သကးဆိုငးရာ View မ္ာ့၏ Layout မ္ာ့နြငးံ Variable အခ္ိဳ႕ကို
assign ်ပဳလုပးခဲံပါသညး၈ သို႕ရာတျငး Cursor တစးခုတညးေဆာကးၿပီ့ေသားလညး့ ထို Cursor မြ မညးသညး႕
အခ္ကးအလကးကိုမြ္ ရရိြႏိုငး်ခငး့မရိြေသ့ေၾကာငးံေသာ ရရိြႏိုငးရနးအတျကး onResume() method ကို
အသဵု့်ပဳရပါမညး၈
တို႕ကို လုပးေဆာငးပါသညး၈ Android life cycle အတျငး့တျငး onResume() ကို Activity တစးခုပျငးံေန
ေသာအခါႏြငးံ အ်ခာ့ေသာ activity မ္ာ့အေပၚတျငး focus ်ဖစးေနေသာအခါတျငး ေခၚယူပါသညး၈
onPause() ကို Activity တစးခုသညး ပိတးၿပီ့ေသားလညး့ ေနာကး Activity တစးခုကို focus ်ပဳလုပးခိုငး့ေစ
လိုေသာအခါတျငး ေခၚယူရပါသညး၈ ထို႕ေၾကာငးံ onResume() method ကို override ်ပဳလုပး်ခငး့်ဖင
database ကို ဖတးရြဳရနးႏြငးံ name field ကိုရယူေစႏိုငးပါသညး၈
if (mCursor != null) {
String title = mText.getText().toString();
mCursor.updateString(NAME_INDEX, title);
mCursor.commitUpdates();
}
}
292 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
package android_programmers_guide.FindAFriend;
import android_programmers_guide.FindAFriend.Friends;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
Cursor mCursor;
EditText mText;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.name_editor);
@Override
protected void onResume() {
super.onResume();
if (mCursor != null) {
mCursor.first();
String title = mCursor.getString(NAME_INDEX);
mText.setText(title);
}
}
@Override
protected void onPause() {
super.onPause();
if (mCursor != null) {
String title = mText.getText().toString();
mCursor.updateString(NAME_INDEX, title);
mCursor.commitUpdates();
မ္ကးပျငးံစာေပ 293
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
}
}
ေဖား်ပပါအခ္ကးအရ Friends database အတျငး့တျငး name value မ္ာ့ကို edit ်ပဳလုပးႏိုငးပါသညး၈ သို႕
ရာတျငး database အတျငး့တျငး အေရ့ႀကီ့ေသာ Field ႏြစးခုရိြၿပီ့ ၁ငး့တို႕မြာ name ႏြငးံ location တို႕်ဖစး
ပါသညး၈ ေနာကးလာမညး႕အပိုငး့တျငး Location Field အတျကး Editor တစးခုကို တညးေဆာကးၾကညး႕ၾက
ပါမညး၈
Location_editor.xml
294 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
android:background="#ffffff"
android:padding="10dip"
android:scrollbars="vertical"
android:fadingEdge="vertical" />
LocationEditor.java
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.Menu;
import android.widget.EditText;
import java.util.Map;
ထို႕ေနာကး Activity ၏ main class outline ကို setup ်ပဳလုပးရပါမညး၈ ၁ငး့အထဲတျငး LocationEditor
အတျကးအသဵု့်ပဳရနးအတျကး define ်ပဳလုပးရနးလိုအပးမညး႕ Variable အမ္ာ့အ်ပာ့ပါွငးပါသညး၈
မ္ကးပျငးံစာေပ 295
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Friends.Friend.NAME, // 2
Friends.Friend.MODIFIED_DATE // 3
};
296 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
super.onDraw(canvas);
}
}
if (mCursor != null) {
mCursor.first();
if (mState == STATE_EDIT) {
setTitle(getText(R.string.title_edit));
} else if (mState == STATE_INSERT) {
setTitle(getText(R.string.title_create));
}
if (mOriginalContent == null) {
mOriginalContent = note;
}
} else {
setTitle(getText(R.string.error_title));
mText.setText(getText(R.string.error_message));
}
}
protected void onPause() {
super.onPause();
if (mCursor != null) {
String text = mText.getText().toString();
int length = text.length();
မ္ကးပျငးံစာေပ 297
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
if (mState == STATE_INSERT) {
String title = text.substring(0, Math.min(30,
length));
if (length > 30) {
int lastSpace = title.lastIndexOf(' ');
if (lastSpace > 0) {
title = title.substring(0, lastSpace);
}
}
mCursor.updateString(NAME_INDEX, title);
}
}
mCursor.updateString(FRIEND_INDEX, text);
managedCommitUpdates(mCursor);
}
}
}
298 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
mCursor = null;
}
}
package android_programmers_guide.FindAFriend;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.Menu;
import android.widget.EditText;
import java.util.Map;
မ္ကးပျငးံစာေပ 299
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
@override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Intent intent = getIntent();
final String type = intent.resolveType(this);
} else if (action.equals(Intent.INSERT_ACTION)) {
mState = STATE_INSERT;
mURI = getContentResolver().insert(intent.getData(), null);
if (mURI == null) {
finish();
return;
}
setResult(RESULT_OK, mURI.toString());
} else {
finish();
return;
}
300 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
setContentView(R.layout.location_editor);
if (icicle != null) {
mOriginalContent = icicle.getString(ORIGINAL_CONTENT);
}
}
@Override
protected void onResume() {
super.onResume();
if (mCursor != null) {
mCursor.first();
if (mState == STATE_EDIT) {
setTitle(getText(R.string.title_edit));
} else if (mState == STATE_INSERT) {
setTitle(getText(R.string.title_create));
}
if (mOriginalContent == null) {
mOriginalContent = note;
} else {
setTitle(getText(R.string.error_title));
mText.setText(getText(R.string.error_message));
}
}
@Override
protected void onFreeze(Bundle outState) {
outState.putString(ORIGINAL_CONTENT, mOriginalContent);
}
@Override
protected void onPause() {
super.onPause();
if (mCursor != null) {
String text = mText.getText().toString();
int length = text.length();
မ္ကးပျငးံစာေပ 301
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
if (mState == STATE_INSERT) {
String title = text.substring(0,
Math.min(30,length));
mCursor.updateString(FRIEND_INDEX, text);
managedCommitUpdates(mCursor);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
if (mState == STATE_EDIT) {
menu.add(0, REVERT_ID, R.string.menu_revert).setShortcut('0',
'r');
if (!mNoteOnly) {
menu.add(0, DELETE_ID,
R.string.menu_delete).setShortcut('1', 'd');
} else {
menu.add(0, DISCARD_ID,
R.string.menu_discard).setShortcut('0','d');
}
if (!mNoteOnly) {
Intent intent = new Intent(null, getIntent().getData());
intent.addCategory(Intent.ALTERNATIVE_CATEGORY);
menu.addIntentOptions(
Menu.ALTERNATIVE, 0,
return true;
}
@Override
public boolean onOptionsItemSelected(Menu.Item item) {
switch (item.getId()) {
case DELETE_ID:
deleteFriend();
finish();
break;
case DISCARD_ID:
cancelFriend();
break;
case REVERT_ID:
302 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
cancelFriend();
break;
}
return super.onOptionsItemSelected(item);
}
မ္ကးပျငးံစာေပ 303
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
style="?android:attr/buttonStyleSmall"
android:text="Sat"
android:layout_alignRight="@+id/myMap"
android:layout_alignBottom="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/buttonZoomOut"
style="?android:attr/buttonStyleSmall"
android:text="-"
android:layout_alignBottom="@+id/myMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
ိdatabase ကိွ
ု ငးေရာကးရနး၇ record မ္ာ့ကိုဖတးရြဳရနးႏြငးံ Overlay ကိုေရ့ဆျရ
ဲ နးအတျကး LoadFriends()
ဟုေခၚသညး႕ method တစးခုကို်ပဳလုပးတညးေဆာကးပါမညး၈ ထို႕ေၾကာငးံေအာကးတျငးေဖား်ပထာ့သညး႕
LoadFriends() method မြ Code မ္ာ့ကိုၾကညး႕ရြဳေလံလာပါ၈ database ကိုဖျငးံ်ခငး့၇ Location Field ကို
match ႏြငးံ parse ်ပဳလုပး်ခငး့၇ location field အတျငး့ရိြ Latitude ႏြငးံ Longitude တို႕တျငး အမြတးတစးခု
တညးေဆာကး်ခငး့တို႕အ်ပငး Overlay တျငး Point တစးခုကိုေရ့ဆျဲ်ခငး့စသညး႕တို႕ကို သတိ်ပဳ၍ မြတးရြဳ
304 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
CharSequence inputStr =
c.getString(c.getColumnIndex("location"));
Matcher matcher = Pattern.matcher(inputStr);
Double.valueOf(groupStr.substring(groupStr.indexOf(":") + 1,
groupStr.indexOf(","))) ;
lngPoint =
Double.valueOf(groupStr.substring(groupStr.indexOf(",") + 1,
groupStr.indexOf("#"))) ;
Point friendLocation = new
Point(latPoint.intValue(),lngPoint.intValue());
drawFriendsOverlay.addNewFriend(c.getString(c.getColumnIndex("name")),
friendLocation);
}
}
}while(c.next());
LocationManager myManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
Double myLatPoint =
myManager.getCurrentLocation("gps").getLatitude()*1E6;
Double myLngPoint =
myManager.getCurrentLocation("gps").getLongitude()*1E6;
myLocation = new Point(myLatPoint.intValue(),myLngPoint.intValue());
drawFriendsOverlay.addNewFriend("Me", myLocation);
mc.centerMapTo(myLocation, false);
mc.zoomTo(9);
mv = null;
}
မ္ကးပျငးံစာေပ 305
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
package android_programmers_guide.FindAFriend;
import android.os.Bundle;
import android.location.LocationManager;
import android.view.View;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.widget.Button;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.graphics.Paint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;
import com.google.android.maps.MapController;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayController;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.friendsmap);
Intent intent = getIntent();
if (intent.getData() == null) {
intent.setData(Friends.Friend.CONTENT_URI);
}
mCursor = managedQuery(getIntent().getData(), PROJECTION, null,null);
306 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
if (c.getString(c.getColumnIndex("location")) != null) {
final String geoPattern = "(geo:[\\-]?[0-9]{1,3}\\.[0
9]{1,6}\\,[\\-]?[0-9]{1,3}\\.[0-9]{1,6}\\#)";
Pattern pattern = Pattern.compile(geoPattern);
CharSequence inputStr =
c.getString(c.getColumnIndex("location"));
Matcher matcher = pattern.matcher(inputStr);
drawFriendsOverlay.addNewFriend(c.getString(c.getColumnIndex("name")),
friendLocation);
}
}
}while(c.next());
LocationManager myManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
Double myLatPoint =
myManager.getCurrentLocation("gps").getLatitude()*1E6;
Double myLngPoint =
myManager.getCurrentLocation("gps").getLongitude()*1E6;
myLocation = new Point(myLatPoint.intValue(),myLngPoint.intValue());
drawFriendsOverlay.addNewFriend("Me", myLocation);
mc.centerMapTo(myLocation, false);
mc.zoomTo(9);
mv = null;
}
မ္ကးပျငးံစာေပ 307
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
}
public void ZoomOut(MapView mv, MapController mc){
if(mv.getZoomLevel()!=1){
mc.zoomTo(mv.getZoomLevel()- 1);
}
}
public void ShowMap(MapView mv, MapController mc){
if (mv.isSatellite()){
mv.toggleSatellite();
}
}
public void ShowSat(MapView mv, MapController mc){
if (!mv.isSatellite()){
mv.toggleSatellite();
}
}
protected class DrawFriendsOverlay extends Overlay{
public String[] friendName = new String[0];
public Point[] friendPoint = new Point[0];
final Paint paint = new Paint();
@Override
public void draw(Canvas canvas, PixelCalculator calculator, Boolean
shadow){
for(int x=0;x<friendPoint.length; x++){
int[] coords = new int[2];
calculator.getPointXY(friendPoint[x], coords);
RectF oval = new RectF(coords[0] - 7, coords[1] + 7,
coords[0] + 7, coords[1] - 7);
paint.setTextSize(14);
canvas.drawText(friendName[x],
coords[0] +9, coords[1], paint);
canvas.drawOval(oval, paint);
}
}
public void addNewFriend(String name,Point point ){
int x = friendPoint.length;
System.arraycopy(friendName, 0, friendNameB, 0, x );
System.arraycopy(friendPoint, 0, friendPointB, 0, x);
friendNameB[x] = name;
friendPointB[x]= point;
}
}
}
308 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
package android_programmers_guide.FindAFriend;
import android_programmers_guide.FindAFriend.Friends;
import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ContentUris;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
မ္ကးပျငးံစာေပ 309
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
import android.view.View.MeasureSpec;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setDefaultKeyMode(SHORTCUT_DEFAULT_KEYS);
setupList();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, INSERT_ID, R.string.menu_insert).setShortcut('3', 'a');
Intent intent = new Intent(null, getIntent().getData());
intent.addCategory(Intent.ALTERNATIVE_CATEGORY);
menu.addIntentOptions(
Menu.ALTERNATIVE, 0, new ComponentName(this, FindAFriend.class),
310 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
final boolean haveItems = mCursor.count() > 0;
if (haveItems) {
Uri uri = ContentUris.withAppendedId(getIntent().getData(),
getSelectedItemId());
Intent[] specifics = new Intent[1];
specifics[0] = new Intent(Intent.EDIT_ACTION, uri);
Menu.Item[] items = new Menu.Item[1];
}
@Override
protected void onListItemClick(ListView l, View v, int position, longid) {
Uri url = ContentUris.withAppendedId(getIntent().getData(), id);
မ္ကးပျငးံစာေပ 311
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
|| Intent.GET_CONTENT_ACTION.equals(action)) {
setResult(RESULT_OK, url.toString());
} else {
312 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
မ္ကးပျငးံစာေပ 313
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
314 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
ေနာကးဆဵု့အခနး့်ဖစးေသာ အခနး့ (ှဿ) တျငး adb command မ္ာ့ႏြငးံ Android Emulator Option
မ္ာ့ကဲံသို႕ေသာ Android SDK ၏ option အခ္ိဳ႕၏ Reference မ္ာ့ကို အသဵု့်ပဳႏိုငးရနးအလို႕ငြါေဖား်ပ
ေပ့ထာ့ပါသညး၈
မ္ကးပျငးံစာေပ 315
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
316 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
Chapter 12
Android SDK Tool Reference
မ္ကးပျငးံစာေပ 317
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
Gprs
Edge
Umts
None
<num>
<min>:<max>
emulator –netfast Shortcut for –netspeed full –netdelay
none
emulator –netspeed <speed> Sets network speed emulator to <speed>.
(The <speed> parameter simulates the
data speed experienced on specific types
of networks) The <speed>s you can use
are as follows:
Gsm
Hscsd
Gprs
Edge
Umts
Hsdpa
Ful
<num>
<up>:<down>
emulator –noaudio Disables Android audio support
emulator –nojni Disables JNI checks in the Dalvik virtual
machine
emulator –noskin Specifies not to use any Emulator skin
emulator –onion <image> Uses overlay image over screen
emulator –onion-alpha <percent> Specifies onion skin translucency value
(as percent)
မ္ကးပျငးံစာေပ 319
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရးဆြဖ
ဲ န္တီးလိုသူမ်ားလက္စြဲ
320 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
instance
adb shell Starts a remote shell in the target
Emulator/ device instance
adb start-server Checks whether the adb server process is
running and, if not, starts it
adb status Reports the current GSM voice/data state
adb unregistered Indicates no network is available
adb version Prints the adb version number
adb voice <state> Changes the state of the GPRS voice
connection to <state>
adb wait-for-bootloader Blocks execution, until the bootloader is
online – that is, until the instance state is
bootloader
adb wait-for-device Blocks execution until the device is online
– that is, until the instance state is device
322 မ္ကးပျငးံစာေပ
ရဲမင္းေအာင္(Ray-Electronic) ANDROID APPLICATION ေရ့ဆျဲဖနးတီ့လိုသူမ္ာ့လကးစျဲ
နိဂဵု့
ယခုစာအုပးတျငး Programming ဘာသာရပးမ္ာ့ကိုေလံလာရာတျငးအသကး်ဖစးေသာ အေ်ခခဵအုတး်မစး်ဖစး
ေသာ အေ်ခခဵသေဘာတရာ့မ္ာ့ႏြငးံတကျ အ်ခာ့ေသာသိသငးံသိထိုကးေသာ၇ တတးသငးံတတးထိုကးေသာ
ဗဟုသုဓမ္ာ့၇ လုပးေဆာငးခ္ကးမ္ာ့ကို ဥပမာမ္ာ့ႏြငးံတကျ ေဖား်ပထာ့ခဲံၿပီ့်ဖစးပါသညး၈ အကယး၍ ယခုစာ
အုပးသညး Programmer တစးဦ့်ဖစးလာေစရနး ၿပီ့်ပညး႕စဵုမႈ ရိြ၇ မရိြ ေမ့်မနး့လာခဲံလြ္ငးမူ လဵု့ွဥႆဵု်ပညး႕စဵု
မႈမရိြေၾကာငး့ ေ်ဖဆိုရမညးသာ ်ဖစးပါသညး၈ Programmer တစးဦ့အ်ဖစး အသကးေမျ့ွမး့ေက္ာငး့်ပဳရနး
ရညးရျယးထာ့သူမ္ာ့ကို အုတးတစးခ္ပး၇ သဲတစးပျငးံမြ္ အေထာကးအကူ်ဖစးလာေစရနး ရညးရျယး၍ ယခုစာအုပး
ကိုေရ့သာ့ခဲံၿခငး့သာ်ဖစးပါသညး၈
ေမတၱာ်ဖငးံ
ရဲမငး့ေအာငး
BE (Electronics)
မ္ကးပျငးံစာေပ 323