You are on page 1of 39

Part 2-b

Android Environment Emulator


Notes are based on: http://developer.android.com/index.html http://developer.android.com/guide/developing/tools/emulator.html

Android Emulator
B Android SDK c cha mt trnh gi lp thit b di ng (mobile device emulator) mt thit b di ng o c th chy trn my tnh ca ta. Emulator cho php ta lm bn mu (prototype), pht trin, v test ng dng Android m khng cn dng mt thit b vt l.

Android emulator gi lp tt c cc tnh nng phn cng v phn mm ca mt thit b di ng in hnh, tr vic n khng th nhn hoc gi cc c in thoi thc v mt s tnh nng khc.
N cung cp cc phm iu khin a dng, ta c th nhn bng chut hoc bn phm sinh ra cc event cho ng dng ca mnh. N cng cung cp mt mn hnh hin th ng dng ca ta cng vi cc ng dng Android khc ang chy.
2

Android Emulator v1.5 Skin


Status Bar Notification Line Power Volume

Tab Launch Pad Menu Home Call Back Hang up


3

Android Emulator v1.6 Skin


Status Bar Notification Line Volume Power Call Hang up

Home

Menu

Back

Tab Launch Pad


4

Android Emulator v1.6 Skin


Tab Launch Pad Status Bar Notification Line Volume Power Call Hang up

Home

Menu

Back

Android Emulator Features


Gi lp in thoi Android th h th nht
Android emulator h tr nhiu tnh nng phn cng thng c ti cc thit b di ng (chng hn HTC-G1), trong c: 1. Mt CPU ARMv5 v b qun l b nh tng ng (memorymanagement unit - MMU) 2. Mt mn hnh LCD 16-bit (gi lp 360 x 480 pixel) 3. Bn phm (mt bn phm Qwerty v cc nt Dpad/Phone lin quan) 4. Mt chip m thanh vi kh nng output v input 5. Cc phn hoch b nh flash (gi lp bng cc file trn a cng ca my tnh ang dng chy gi lp) 6. Mt modem GSM, gm c mt th SIM c gi lp

Android Emulator Features


Nexus One (newer Google developer phone)

Some phones in the market already surpass these specs (Fall 2010) 7

Android Virtual Devices and the Emulator


dng emulator, trc ht ta phi to mt hoc vi cu hnh thit b o (ADV). Mi cu hnh quy nh platform Android platform s chy trong emulator, tp cc ty chn phn cng, v b ngoi ca emulator. Sau , khi bt emulator, ta ch ra cu hnh AVD ta mun np vo emulator. Mi AVD c chc nng nh mt thit b c lp, vi ni lu tr ring dnh cho d liu ngi dng, SD card, v.v.. Khi ta bt emulator vi mt cu hnh AVD, n s t ng np d liu ngi dng v SD card. Ta c th to s lng AVD ty theo nhu cu, da trn cc loi thit b m ta mun m hnh ha, cc Android platform v th vin ngoi m ta mun chy ng dng trn . to v qun l cc AVD, ta dng AVD Manager UI hoc android tool c trong SDK. Chi tit xem ti Managing Virtual Devices (http://developer.android.com/guide/developing/devices/index.html)
8

Starting Stopping the Emulator


start mt thc th ca emulator t dng lnh, chuyn ti th mc tools/ ca SDK. G lnh emulator nh sau: emulator -avd <avd_name> Lnh ny s khi to emulator v np mt cu hnh AVD. Sau vi giy, ta s thy ca s emulator hin trn mn hnh. Nu ang dng Eclipse, khi ta run hoc debug ng dng, ADT plugin cho Eclipse s t ng ci ng dng ca ta v chy emulator.

stop mt thc th emulator, ta ch cn ng ca s emulator.


lit k tt c cc AVD hin c, dng lnh DOS android list avd
9

Controlling the Emulator


Keyboard Escape Home F2, PageUp Shift-F2, PageDown F3 F4 F5 F7 Ctrl-F3, Ctrl-KEYPAD_5 Ctrl-F5, KEYPAD_PLUS Ctrl-F6, KEYPAD_MINUS KEYPAD_5 KEYPAD_4 KEYPAD_6 KEYPAD_8 KEYPAD_2 F8 F9 Alt-ENTER Ctrl-T Ctrl-F11, KEYPAD_7 Ctrl-F12, KEYPAD_9 OS function Back button Home button Menu (Soft-Left) button Start (Soft-Right) button Call/Dial button Hangup / EndCall button Search button Power button Camera button Volume up button Volume down button DPad center DPad left DPad right DPad up DPad down toggle cell network on/off toggle code profiling (when -trace option set) toggle FullScreen mode toggle trackball mode switch to previous layout switch to next layout

Keypad keys only work when NumLock is deactivated.

10

Working with Emulator Disk Images


Emulator dng cc disk image lu trn my tnh gi lp b nh flash (hoc nhng th tng t) ca thit b thc. V d, n dng disk image c cha: Mt nhn h iu hnh c th ca emulator, H thng Android, ram-disk image, v cc image ghi c dnh cho d liu ca ngi dng v SD card gi lp. Mi AVD c mt b disk image ca ring n.
11

Working with Emulator Disk Images


Mc nh, emulator lun tm disk image ti vng lu tr ring ca AVD ang chy Nu cha c image no khi emulator c bt, n s to cc image ti th mc AVD da theo cc phin bn mc nh lu trong SDK.

Ni lu tr mc nh ca cc AVD:
~/.android/avd i vi OS X v Linux, C:\Documents and Settings\<user>\.android\avd\... i vi Windows XP, v C:\Users\<user>\.android\ ti Windows Vista.
12

AVD - Android Virtual Devices


Mi Android Virtual Device (AVD) l mt cu hnh ca cc ty chn emulator, cho php ta m hnh ha mt thit b thc.

Mi AVD gm c:
Hardware profile. Ta c th t ty chn quy nh cc tnh nng phn cng ca thit b o. V d, ta c th quy nh xem thit b c camera hay khng, n dng bn phm QWERTY vt l hay mt dialing pad, kch thc b nh ca n, v.v.. nh x ti mt system image. Ta c th quy nh phin bn Android platform s chy trn thit b o. Ta c th chn mt phin bn ca Android platform chun hoc system image ng gi cng vi mt SDK add-on. Cc ty chn khc. Ta c th quy nh emulator skin, kch thc mn hnh, v.v.. SD card gi lp s dng km vi AVD. Mt vng lu tr dnh ring trn my tnh ca ta, ni dnh lu d liu ngi dng ca thit b (cc ng dng ci, cu hnh, v.v..) v SD card 13 gi lp.

Creating an AVD using the Eclipse-ADT Tool


From Eclipse, follow the sequence: Main menu (AVD Manager > Virtual Devices > New > Provide a Name, choose an Android target, create a new SD card with about 2Gb, choose a screen type, add hardware devices Click on: Create AVD (wait, it takes several minutes to format the new SD card) )

14

Creating an AVD using the android tool


Khi to mt AVD, ta dng lnh: android create avd -n <avd_name> -t <targetID> -c <size>[K|M] Tham s t (target) quy nh system image m ta mun dng mi khi bt AVD ny. V sau, mi khi ng dng dng AVD ny, chng s chy trn h thng m ta quy nh bi tham s -t. bit targetID ca cc system image c th dng, ta c th dng cng c android lit k cc system image hin c cng vi target ID ca chng: android list targets
15

Creating an AVD using the android tool


Example: Creating an AVD using the android tool Sau khi xem danh sch cc target, gi s ta quyt nh s to mt profile da trn target id:4 h tr SDK1.6 vi th vin Google API Mapping. Cn c thm mt SD card dung lng 1Gig. Ta dng lnh sau

android create avd -n myAVD4SD1G -t 4 -c 1024M

16

Creating an AVD using the android tool


Example: Creating an AVD using the android tool Xem h thng hin c nhng AVD no:

17

SD Card Emulation
Ta c th to mt disk image v sau np n vo emulator khi khi ng, gi lp s c mt ca mt SD card trong thit b. Emulator h tr cc th SDHC card gi lp, do ta c th to mt SD card image vi kch thc ty min khng vt qu 128 gigabyte. Ta c th dng adb hoc emulator duyt cy th mc, gi file ti, v chp/xa file trong SD card.

To mt SD card image bng mksdcard Dng cng c mksdcard c sn trong SDK to cc disk image dng FAT32. mksdcard <size> <file> V d: mksdcard 1024M c:/temp/mysdcard.iso
18

SD Card Emulation
Android Emulator How to use the SDCARD device C php chung to mt SD card l

mksdcard [ -l label ] <size> <file>


Cng c mksdcard l mt phn ca Android SDK. SD label l khng bt buc. Kch thc thit b l s nguyn, theo sau l K (kilobyte) hoc M (megabyte).

V d: To mt thit b SDcard 1GB bng lnh sau mksdcard 1024M c:\mysdcard.img Chy emulator bng lnh emulator -sdcard c:\mysdcard.img Hoc emulator -avd myAvdFile

19

SD Card Emulation
Moving Data, Music and Pictures to the Sdcard
1.Dng chng trnh ddms y file vo SDcard (vi iu kin emulator ang chy v SD card ang gn vi n). 2.Click: Device > File Explorer, dn ti mt ca s mi, ti ta chn SDcard. 3.By gi ta chuyn d liu vo sdcard. C cc la chn sau Dng Windows Explore ko & th file v th mc vo card, hoc Nhn nt "Push File onto Device" (see upper left icons: push, pull, delete).
( DDMS stands for Dalvik Debug Monitor Services. The program is located in the /tools folder of the SDK. Also available in Eclipse perspective Top upper right icons) 20

SD Card Emulation
Moving Data, Music and Pictures to the SDcard

21

SD Card Emulation
Moving Data, Music and Pictures to the SDcard
4. Quay li emulator. Ta s thy cc file nhc (c nh du) trong SDcard

22

SD Card Emulation
Moving Data, Music and Pictures to the SDcard
5. nh hin ra khi click Application Pad v bt ng dng Gallery

23

Login into the OS shell


Ta c th ng nhp vo phin bn Linux ca Android ang chy trong emulator v thc hin cc lnh. 1.Chy emulator 2.Chy ng dng adb c:> adb shell

(adb l ng dng Android Debug Bridge. N nm trong th mc /tools ca SDK)

24

Login into the OS shell


Nu c vi emulator ang chy (hoc in thoi vt l ang ni vi my tnh qua cp USB) ta cn ch nh thit b ch. Thc hin cc bc: 1.Lit k danh sch cc emulator ang chy: adb devices
List of devices emulator-5554 emulator-5556 HT845GZ45737 attached device device device

2.Chy ng dng adb: adb -s emulator-5554

shell

25

Login into the OS shell


3. Android chp nhn nhiu lnh shell ca Linux, trong c cc lnh hu ch sau
ls ................. mkdir .............. rmdir .............. rm -r .............. rm ................. mv ................. cat ................ cd ................. pwd ................ df ................. chmod .............. date ............... exit ............... show directory (alphabetical order) make a directory remove directory to delete folders with files remove files moving and renaming files displaying short files change current directory find out what directory you are in shows available disk space changes permissions on a file display date terminate session

26

Login into the OS shell


4. Khng c lnh copy (cp) trong Android, thay vo , ta c th dng lnh cat. V d: # cat data/app/theInstalledApp.apk > cache/theInstalledApp.apk

27

Android Emulator
Lu #1: Emulators & Hardware Devices
Ta c th test ng dng ti mt emulator phn mm hoc thit b phn cng. Nu dng phn cng, xem hng dn thit lp mi trng ti link di y. http://developer.android.com/guide/developing/device.html Ti ca s dng lnh, g lnh: adb devices ta s thy dng tng t HT845GZ45737 device cho thy s c mt ca thit b phn cng.

Ly quyn Root ti thit b phn cng


in thoi dnh cho developer nh G1 m quyn root.

Chy ng dng terminal ( adb shell ) v xem c du nhc # hay khng; nu khng c, th dng lnh su. Nu lnh khng cho du nhc root m li bo li permission denied th c ngha l ta khng c quyn root truy nhp thit b.

28

Android Emulator
Lu #2: Chuyn mt ng dng t thit b (rooted) sang Emulator
chuyn ng dng c ci ti in thoi c quyn root, thc hin cc bc sau: 1.Chy ca s lnh: > adb devices (tm id ca thit b, chng hn HT845GZ45737 ) 2.Ly file t thit b vo h thng file my tnh. adb -s HT845GZ45737 pull data/app/theInstalled.apk c:/theInstalled.apk 3.Tho cp ni vi in thoi 4.Chy emulator 5.Ci ng dng vo emulator adb -s emulator-5554 install c:\theInstalledApp.apk adb -s emulator-5554 uninstall data/app/theInstalled.apk Ta s thy mt thng ip thng bo kch thc ca gi c ci, v Success.
29

Using the Emulator with inserted SD card from Eclipse


From Eclipses menu create new launch configuration: Run > Run Configurations > New icon
On the Target panel 1. Select existing Android Virtual device (AVD) 2. Enter additional Command Line Options (see caption) 3. Apply > Run
Additional Emulator Command Line Options: -sdcard c:\Android_Emulator_Data\mysdcard.img -datadir c:\Android_Emulator_Data

30

Sending Text Messages to the Emulator


1.Start the emulator. 2.Open a new shell and type : c:> adb devices so you know the emulators numeric port id (usually 5554, 5556, and so on)
3.Connect to the console using telnet command like: c:> telnet localhost 5554 4.After receiving the telnet prompt you can send a text message with the command (no quotes needed for the message) sms send <Senders phone number> <text message>

31

Sending Text Messages to the Emulator


Example:

32

Making a Voice Call to the Emulator


1.Start the emulator. 2.Open a new shell and type : adb devices to know the emulators numeric port id (usually 5554, 5556, and so on)
3.Connect to the console using telnet command like: telnet localhost 5554 (this is the number to be called) 4.After receiving the telnet prompt you can place a call (voice) with the command gsm call <callers phone number>

33

Making a Voice Call to the Emulator


Example:

34

Using Eclipses DDMS facility


Emulator Control Ta c th gi lp cc trng thi v hot ng c bit ca thit b. Cc tnh nng bao gm: 1.Telephony Status thay i trng thi cu hnh Voice and Data ca thit b (home, roaming, tm kim, v.v..), v gi lp cc loi mng khc nhau (GPRS, EDGE, UTMS, v.v..). 2.Telephony Actions thc hin cc c gi v tin nhn SMS gi lp ti emulator. 3.Location Controls gi d liu gi v v tr cho emulator ta c th thc hin cc thao tc lin quan n a im nh GPS mapping. dng Location Controls, chy ng dng ca mnh ti Android emulator v m DDMS. Click tab Emulator Controls v ko xung Location Controls. T y, ta c th: Gi tng ta kinh /v cho thit b. Click Manual, chn nh dng ta (coordinate format), in vo cc trng v click Send. Dng mt file GPX m t mt tuyn ng cn playback cho device.

35

Using Eclipse to test Emulators Telephony Actions

36

Android Emulator

Questions ?

37

Android Emulator
Appendix 1 Kt ni thit b phn cng vi my tnh
1.Dng cp mini-USB ni thit b vi my tnh 2.M rng Notification bar 3.Mount thit b Ta cn c th dng Eclipse-ADT-File Explorer ghi/c file vi thit b.

38

Android Emulator
Appendix 1 Lin lc gia cc Emulator
1.Chy hai thc th emulator (ID thng l: 5554, 5556, ) 2.Quay s (hoc gi SMS) t emulator ny (chng hn 5554) ti emulator kia (5556) 3.Nhn cc nt gi Xanh lc/ nhn/kt thc cuc gi 4.Th gi SMS (dng cc s 5554 v 5556)

39

You might also like