Using SDK Tools for Everyday Development

The SDK tools are the building blocks you use in developing Android apps. New features packed into every release enable you to develop for the latest version of Android.

Saying hello to the emulator

Google provides not only the tools you need to develop apps but also an awesome little emulator to test your app. The emulator has some limitations (for example, it cannot emulate certain hardware components, such as the accelerometer) but not to worry — plenty of apps can be developed and tested using only an emulator.

When you’re developing an app that uses Bluetooth, for example, you should use a physical device that has Bluetooth on it. If you develop on a speedy computer, testing on an emulator is fast; on slower machines, however, the emulator can take a long time to complete a seemingly simple task. If you’re developing on an older machine, use a physical device. When you’re developing on a newer, faster machine, use the emulator.

The emulator is handy for testing apps at different screen sizes and resolutions. It isn’t always practical or possible to have several devices connected to your computer at the same time, but you can run multiple emulators with varying screen sizes and resolutions.

Getting physical with a real Android device

The emulator is awesome, but sometimes you need a physical device for testing. The Dalvik Debug Monitor Server, or DDMS, allows you to debug your app on an actual device, which comes in handy for developing apps that use hardware features that aren’t, or can’t be, emulated. Suppose that you’re developing an app that tracks the user’s location. You can send coordinates to the device manually, but at some point in your development, you probably want to test the app to find out whether it, in fact, displays the correct location. Using an actual device is the only way to do it.

If you develop on a Windows machine and you want to test your app on a real-life device, you need to install a driver. If you’re on a Mac or Linux machine, you can skip this section because you don’t need to install the USB driver.

To download the Windows USB driver for Android devices, follow these steps:

1. In Eclipse, choose Window → Android SDK Manager.

The Android SDK Manager dialog box opens, as shown in Figure 2-18.

2. Expand the Extras repository, and select the Google USB Driver package.

3. Click the Install Packages button.

The Choose Packages to Install dialog box opens, as shown in Figure 2-19.

Figure 2-18: Available packages.

9781118417454-fg0218.eps

4. Select the Accept radio button to accept the license, and then click the Install button.

The Installing Archives dialog box opens, displaying a progress bar.

Figure 2-19: Click the Install button.

9781118417454-fg0219.eps

5. When the package finishes downloading and installing, click the Close button.

6. Exit the Android SDK Manager dialog box.

Debugging your work

The DDMS equips you with the necessary tools to find those pesky bugs, allowing you to go behind the scenes as your app is running to see the state of its hardware, such as the wireless radio. But wait — there’s more! The DDMS also simulates actions normally reserved for physical devices, such as sending global positioning system (GPS) coordinates manually, simulating phone calls, or simulating text messages. Get all the DDMS details at http://developer.android.com/guide/developing/debugging/ddms.html .

Trying out the API and SDK samples

The API and SDK samples are provided to demonstrate how to use the functionality provided by the API and SDK. If you’re ever stuck and can’t figure out how to make something work, visit http://developer.android.com/resources/samples/index.html to find samples of almost anything, from using Bluetooth to making a two-way text application or a 2D game.

You also have a few samples in your Android SDK. Simply open the Android SDK and navigate to the samples directory, which contains various samples that range from interacting with services to manipulating local databases. Spend some time playing with the samples — the best way to learn to develop Android applications is to look at existing working code bases and then experiment with them in Eclipse.

Giving the API demos a spin

The API demos inside the samples folder in the SDK are a collection of apps that demonstrate how to use the included APIs. You can find sample apps with a ton of examples, such as

check.png Notifications

check.png Alarms

check.png Intents

check.png Menus

check.png Search

check.png Preferences

check.png Background services

If you get stuck or you simply want to prepare yourself for writing your next spectacular Android application, check out the complete details at http://developer.android.com/resources/samples/ApiDemos/index.html .

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset