1. Trang chủ
  2. » Công Nghệ Thông Tin

Bắt Đầu Với Android (P.8) docx

36 237 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 36
Dung lượng 2,16 MB

Nội dung

CHAPTER 37 ■ DEVELOPMENT TOOLS 327 The hairlines (cyan) overlaying the activity show the position being zoomed upon—just click on a new area to change where the Loupe View is inspecting. Of course, there is another slider to adjust how much the Loupe View is zoomed. Delightful Dalvik Debugging Detailed, Demoed Another tool in the Android developer’s arsenal is the Dalvik Debug Monitor Service (DDMS). This is a “Swiss Army knife,” allowing you to do everything from browse log files, update the GPS location provided by emulator, simulate incoming calls and messages, and browse the on- emulator storage to push and pull files. DDMS has a wide range of uses, so this section will not try to cover them all, rather it will cover the most useful at the time of writing. To launch DDMS, run the ddms program inside the tools/ directory in your Android SDK distribution. It will initially display just a tree of emulators and running programs on the left (see Figure 37-7). Figure 37-7. DDMS initial view Murphy_2419-8C37.fm Page 327 Thursday, May 14, 2009 4:53 PM 328 CHAPTER 37 ■ DEVELOPMENT TOOLS Clicking on an emulator allows you to browse the event log on the bottom and manipulate the emulator via the tabs on the right as shown in Figure 37-8. Figure 37-8. DDMS, with emulator selected Logging Rather than use adb logcat, DDMS lets you view your logging information in a scrollable table. Just highlight the emulator or device you want to monitor, and the bottom half of the screen shows the logs (see Figure 37-9). In addition, you can: • Filter the Log tab by any of the five logging levels, shown as the V through E toolbar buttons. • Create a custom filter, so you can view only those tagged with your application’s tag, by pressing the + toolbar button and completing the form. The name you enter in the form will be used as the name of another logging output tab in the bottom portion of the DDMS main window. • Save the log information to a text file for later perusal, or for searching. Murphy_2419-8C37.fm Page 328 Thursday, May 14, 2009 4:53 PM CHAPTER 37 ■ DEVELOPMENT TOOLS 329 Figure 37-9. DDMS logging filter File Push and Pull While you can use adb pull and adb push to get files to and from an emulator or device, DDMS lets you do that visually. Just highlight the emulator or device you wish to work with, then choose Device ➤ File Explorer from the main menu. That will bring up the typical directory browser seen in Figure 37-10. Figure 37-10. DDMS File Explorer Murphy_2419-8C37.fm Page 329 Thursday, May 14, 2009 4:53 PM 330 CHAPTER 37 ■ DEVELOPMENT TOOLS Just browse to the file you want and click either the pull (left-most) or push (middle) toolbar button to transfer the file to/from your development machine. Or, click the delete (right-most) toolbar button to delete the file. There are a few caveats to this: • You cannot create directories through this tool. You will either need to use adb shell or create them from within your application. • While you can putter through most of the files on an emulator, you can access very little outside of /sdcard on an actual device, due to Android security restrictions. Screenshots To take a screenshot of the Android emulator or device, simply press <Ctrl>-<S> or choose Device ➤ Screen capture from the main menu. This will bring up a dialog box containing an image of the current screen shown in Figure 37-11. Figure 37-11. DDMS screen capture From here, you can click Save to save the image as a PNG file somewhere on your develop- ment machine, Refresh to update the image based on the current state of the emulator or device, or Done to close the dialog. Murphy_2419-8C37.fm Page 330 Thursday, May 14, 2009 4:53 PM CHAPTER 37 ■ DEVELOPMENT TOOLS 331 Location Updates To use DDMS to supply location updates to your application, the first thing you must do is have your application use the gps LocationProvider, as that is the one that DDMS is set to update. Then, click on the Emulator Control tab and scroll down to the Location Controls section. Here, you will find a smaller tabbed pane with three options for specifying locations: Manual, GPX, and KML (see Figure 37-12). Figure 37-12. DDMS location controls 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 loca- tion 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. Murphy_2419-8C37.fm Page 331 Thursday, May 14, 2009 4:53 PM 332 CHAPTER 37 ■ DEVELOPMENT TOOLS 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. 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. Murphy_2419-8C37.fm Page 332 Thursday, May 14, 2009 4:53 PM CHAPTER 37 ■ DEVELOPMENT TOOLS 333 Figure 37-14. Simulated incoming call Figure 37-15. Simulated text message Murphy_2419-8C37.fm Page 333 Thursday, May 14, 2009 4:53 PM 334 CHAPTER 37 ■ DEVELOPMENT TOOLS 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 Put it On My Card 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. Creating a Card Image 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: Murphy_2419-8C37.fm Page 334 Thursday, May 14, 2009 4:53 PM CHAPTER 37 ■ DEVELOPMENT TOOLS 335 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 Inserting the Card 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. Murphy_2419-8C37.fm Page 335 Thursday, May 14, 2009 4:53 PM Murphy_2419-8C37.fm Page 336 Thursday, May 14, 2009 4:53 PM [...]... E X Android Beginners, 337 android create project, 340 Android Developers, 337 Android Discuss, 337 Android Interface Description Language (AIDL), 275–276 #android IRC channel, 337 android update project, 340 Android Virtual Device (AVD) system, 339–340 android: apiKey attribute, 300 android. app.Activity base class, 17 android. app.default_searchable property, 320 android: authorities property, 267 android: autoText... ■I N D E X android: singleLine property, 30 android: spacing property, 69 android: spinnerSelector property, 69 android: src property, 28 android: stretchColumns property, 50 android: stretchMode property, 62 android: text property, 23 android: textColor property, 27, 31 android. text.Spanned interface, 177 android: textStyle property, 27 android: title property, 122 android: typeface property, 27, 127 android: value... 62 android: numeric property, 30 android: orderInCategory attribute, 122 android: orientation property, 37 android: padding property, 39 android: password property, 30 android: permission attribute, 270–271, 277 android: phoneNumber property, 30 android. R.drawable prefix, 181 android: reqFiveWayNav configuration, 341 android: reqHardKeyboard configuration, 341 android: reqKeyboardType configuration, 341 android: reqNavigation... android: autoText property, 29 android: background property, 35 AndroidBrowser class, 227 android: capitalize property, 29 android: clickable property, 300 android: collapseColumns property, 50 android: columnWidth property, 62 android: completionThreshold property, 66 android: configChanges property, 244 android: digits property, 30 android: drawSelectorOnTop property, 59, 69 android: enabled attribute, 122 android: id attribute,... 44, 48 android: layout_alignRight property, 46 android: layout_alignTop property, 46 android: layout_below property, 45 android: layout_centerHorizontal property, 45 android: layout_centerInParent property, 45 android: layout_centerVertical property, 45 android: layout_column property, 49 android: layout_gravity property, 38 android: layout_height property, 23, 38, 46, 101 android: layout_span property, 49 android: layout_toLeftOf... 22–23, 122, 300 android: inputMethod property, 30 android. intent.action.SEARCH property, 320 android: layout_above property, 45 android: layout_alignBaseline property, 46–47 android: layout_alignBottom property, 46 android: layout_alignLeft property, 46 android: layout_ alignParentBottom property, 44 android: layout_alignParentLeft property, 45 android: layout_alignParentRight property, 45 android: layout_alignParentTop... DZone for android and subscribe to a feed12 based on that search You might also consider keeping tabs on those mentioning Android in Twitter messages, such as by using a Summize feed.13 5 6 7 8 9 10 11 12 13 http://source .android. com http://source .android. com/download http://git.source .android. com/ http://source .android. com/report-bugs http://source .android. com/submit-patches http://source .android. com/discuss... way: • android: reqFiveWayNav to indicate you need a 5-way navigation pointing device of some form (e.g., android: reqFiveWayNav="true") • android: reqNavigation to restrict the 5-way navigation pointing device to a specific type (e.g., android: reqNavigation="trackball") • android: reqHardKeyboard to specify if a hardware (physical) keyboard is required (e.g., android: reqHardKeyboard="true") • android: reqKeyboardType,... android: reqNavigation configuration, 341 android: reqTouchScreen configuration, 341 android. resource://com.example.app/ ., where com.example.app string, 181 android. resource://com.example.app/raw/ , where com.example.app string, 181 android. R.layout.simple_list_item_1 property, 56 android. R.layout.simple_spinner_item property, 60 android: screenOrientation property, 249 android: shrinkColumns property, 50... property, 45 android: layout_toRightOf property, 45 android: layout_weight property, 38 android: layout_width property, 23, 38, 41, 46 AndroidManifest.xml (manifest) file adding services to, 276–277 application element, 10–11 defined, 7 enforcing permissions via, 271–272 manifest element, 9–10 overview, 9 uses-sdk element, 11–12 android: menuCategory attribute, 122 android: name property, 11, 266, 320 android: numColumns . http://source .android. com 6. http://source .android. com/download 7. http://git.source .android. com/ 8. http://source .android. com/report-bugs 9. http://source .android. com/submit-patches 10. http://source .android. com/discuss 11 anddev.org 4 •The #android IRC channel on freenode 1. http://groups.google.com/group /android- beginners 2. http://groups.google.com/group /android- developers 3. http://groups.google.com/group /android- discuss 4 assistance with Android are the Android Google Groups. With respect to the SDK, there are three to consider following: • Android Beginners, 1 a great place to ask entry-level questions • Android Developers, 2

Ngày đăng: 05/07/2014, 21:20