The Manual tab is fairly self-explanatory: provide a latitude and longitude and click the Send button to submit that location to the emulator. The emulator, in turn will notify any location listeners of the new position.
Discussion of the GPX and KML options is beyond the scope of this book.
Placing Calls and Messages
If you want to simulate incoming calls or SMS messages to the Android emulator, DDMS can handle that as well.
On the Emulator Control tab, above the Location Controls group, is the Telephony Actions group (see Figure 37-13).
Figure 37-13. DDMS telephony controls
To simulate an incoming call, fill in a phone number, choose the Voice radio button, and click Call. At that point, the emulator will show the incoming call, allowing you to accept it (via the green phone button) or reject it (via the red phone button) seen in Figure 37-14.
Figure 37-14. Simulated incoming call
To simulate an incoming text message, fill in a phone number, choose the SMS radio button, enter a message in the provided text area, and click Send. The text message will then appear as a notification as shown in Figure 37-15.
Figure 37-15. Simulated text message
Of course, you can click on the notification to view the message in the full-fledged Messaging application as you can see in Figure 37-16.
Figure 37-16. Simulated text message, in Messaging application
The T-Mobile G1 has a microSD card slot. Many other Android devices are likely to have similar forms of removable storage, which the Android platform refers to generically as an “SD card”.
SD cards are strongly recommended to be used by developers as the holding pen for large data sets: images, movie clips, audio files, etc. The T-Mobile G1, in particular, has a relatively paltry amount of on-board flash memory, so the more you can store on an SD card, the better.
Of course, the challenge is that, while the G1 has an SD card by default, the emulator does not. To make the emulator work like the G1, you need to create and “insert” an SD card into the emulator.
Rather than require emulators to somehow have access to an actual SD card reader and use actual SD cards, Android is set up to use card images. An image is simply a file that the emulator will treat as if it were an SD card volume. If you are used to disk images used with virtualization tools (e.g., VirtualBox), the concept is the same: Android uses a disk image representing the SD card contents.
To create such an image, use the mksdcard
utility, provided in the tools/
directory of your SDK installation. This takes two main parameters:
1. The size of the image, and hence the size of the resulting “card.” If you just supply a number, it is interpreted as a size in bytes. Alternatively, you can append K
or M
to the number to indicate a size in kilobytes or megabytes, respectively.
2. The filename under which to store the image.
For example, to create a 1GB SD card image, to simulate the G1’s SD card in the emulator, you could run:
mksdcard 1024M sdcard.img
To have your emulator use this SD card image, start the emulator with the -sdcard
switch, containing a fully-qualified path to the image file you created using mksdcard
. While there will be no visible impact — there is no icon or anything in Android showing that you have a card mounted — the /sdcard
path will now be available for reading and writing.
To put files on the /sdcard
, either use the File Explorer in DDMS or adb push
and adb pull
from the console.
CHAPTER 38
Where Do We Go from Here?
Obviously, this book does not cover everything. And while your number-one resource (besides the book) is going to be the Android SDK documentation, you are likely to need information beyond what’s covered in either of those places.
Searching online for “android” and a class name is a good way to turn up tutorials that reference a given Android class. However, bear in mind that tutorials written before late August 2008 are probably written for the M5 SDK and, therefore, will require considerable adjustment to work properly in current SDKs.
Beyond randomly hunting around for tutorials, though, this chapter outlines some resources to keep in mind.
Questions. Sometimes with Answers.
The official places to get assistance with Android are the Android Google Groups. With respect to the SDK, there are three to consider following:
• Android Beginners, [34] http://groups.google.com/group/android-beginners
a great place to ask entry-level questions
• Android Developers, [35] http://groups.google.com/group/android-developers
best suited for more-complicated questions or ones that delve into less-used portions of the SDK
• Android Discuss, [36] http://groups.google.com/group/android-discuss
designed for free-form discussion of anything Android-related, not necessarily for programming questions and answers
You might also consider these:
• The Android tutorials and programming forums at anddev.org [37] http://anddev.org/
• The #android
IRC channel on freenode
The source code to Android is now available. Mostly this is for people looking to enhance, improve, or otherwise fuss with the insides of the Android operating system. But, it is possible that you will find the answers you seek in that code, particularly if you want to see how some built-in Android component does its thing.
The source code and related resources can be found at the Android Open Source Project Web site. [38] http://source.android.com
Here, you can
• Download [39] http://source.android.com/download
or browse [40] http://git.source.android.com/
the source code
• File bug reports [41] http://source.android.com/report-bugs
against the operating system itself
• Submit patches [42] http://source.android.com/submit-patches
and learn about the process for how such patches get evaluated and approved
Читать дальше