Designing an App Widget

The Android SDK provides developers with an interesting way to provide functionality outside the traditional boundaries of a mobile application by using App Widgets. Developers can use the App Widget API to create mini controls or views that can be added to the user's Home screen. These simple controls can provide a user with information about the application and remind the user to launch the application when necessary. App Widgets can be useful for certain types of applications, such as those...

Testing Best Practices

Mobile users expect a lot from today's mobile applications. They expect the applications they install to be stable, responsive, and secure. Stable means that the application works and doesn't crash or mess up the user's phone. Responsive means the phone always responds to key presses, and long operations use progress bar indicators. Secure means that the application doesn't abuse the trust of the user, either intentionally or unintentionally. Users expect an application to have a reasonably...

Developing Coding Standards

When developers have and follow some guidelines, their code is more cohesive and easy to maintain. Developing a set of well-communicated coding standards for development can help drive home some of the important requirements of mobile applications. For example, developers might want to do the following Discuss and come up with a common way for all developers to implement error and exception handling. Move lengthy or process-intensive operations off the main UI thread. Release objects and...

Designing the Favorite Place Feature

Mobile users are always on the go, and mobile applications that include integration with LBS have become incredibly popular. The Android platform makes it simple to add LBS support to applications. The degree to which LBS support is incorporated into an application is a design choice for the developer, and there are a number of options. Because the Been There, Done That application is primarily a game, you want to include some of the most common LBS features. You do this by adding a favorite...

Using a Defect Tracking System

A defect tracking system provides a way to organize and keep track of application bugs, called defects, and is generally used along with a process for resolving these defects. Resolving a defect generally means fixing the problem and verifying that the fix is correct in a future build. With mobile applications, defects come in many forms. Some defects occur on all handsets, while others occur only on specific handsets. Functional defects that is, features of an application that are not working...

Enabling Location Testing on the Emulator

Many LBS features are available to developers without the special Google developer accounts and API keys. For example, you need a special API key to use Google Maps within an application, but you do not need any special permission to launch an Intent object to view a location that can be matched to any Map applications on the device. Creating an AVD with Google APIs and Applications You may have noticed that the basic Android installation (the target platform chosen when creating an AVD for use...

Reading Raw Sensor Data

The following are some of the device sensors that the Android SDK supports Accelerometer Measures acceleration in three dimensions Light sensor Measures brightness (which is useful for camera flashes) Magnetic field sensor Measures magnetism in three dimensions Orientation sensor Measures a device's orientation Temperature sensor Measures temperature Proximity sensor Measures the distance from the device to a point in space The Android emulator does not simulate any device sensors natively, but...

Working with View Switcher Controls

For situations in which an activity is going to be updating the content of a View control repeatedly, the Android SDK provides a mechanism called a ViewSwitcher control. Using a ViewSwitcher is an efficient way to update content on a screen. A ViewSwitcher control has two children and handles transition from the currently visible child view to the next view to be displayed. The child View controls of a ViewSwitcher control can be generated programmatically using ViewFactory. There are two...

App WidgetProvider class

309-311 ARCHOS 5 Internet tablet, 402 assertTrueO method, 377 assets resources, 74 definition of, 73 assets folder, 12 asynchronous tasks, running with AsyncTask class, 265-266 with threads and handlers, 266 AsyncTask class, 265-266, 282-285, 288, 297-298 audio, 353 authors' contact information, 425 authors' website, 424-425 Auto-complete feature, 416 automated testing, 373 adding more tests, 379-380 creating test cases, 375-377 creating test projects, 374-375 explained, 374 logging application...

Retrieving Telephony Information

Developers can leverage the TelephonyManager class (android.telephony.TelephonyManager) to access network status information about the device programmatically. You can get an instance of TelephonyManager by using the familiar getSystemService() method of the application's Context object TelephonyManager telMgr (TelephonyManager) getSystemService(Context. TELEPHONY_SERVICE) Once you have a valid instance of TelephonyManager, you can request the detailed information about the device and its...

Answers

The ViewSwitcher class has two subclasses TextSwitcher (for animating between two TextView controls) and ImageSwitcher (for animating between two ImageView controls). 2. False. The TextView controls displayed by a TextSwitcher control can be created on-the-fly by using ViewFactory. 3. True. Many standard Java packages are available within the Android SDK. There are also a number of packages specially designed for Android under the android.* package tree. See the Android SDK...

Designing the Avatar Feature

Many mobile applications today are networked and have some social component. One way for users to differentiate themselves from others is by setting custom icons to represent who they are. To give users this ability, you can implement the avatar feature on the settings screen. Avatars come in many forms an avatar may be a close-up photograph of the user's face, or it might be a funky graphic that speaks to the user's personality. To incorporate of the avatar feature into the Been There, Done...

Testing on the Emulator

A test team cannot be expected to set up testing environments on every carrier or in every country where users will use an application. There are times when using the Android emulator can reduce costs and improve testing coverage. The following are some of the benefits of using the emulator Rapidly testing when a target handset is not available (or is in short supply). Simulating handsets when they are not yet available (for example, preproduc-tion phones). Testing difficult or dangerous...

Developing Good Test Plans

Testers must rely heavily on an application's functional specification, as well as any user interface documentation, to determine whether features and functionality have been properly implemented. The application features and workflow must be thoroughly documented at the screen level and then validated by testing. In larger teams, it is not uncommon for interpretive differences to exist between the functional specification, the developer's implementation, and the tester's resulting experience....

Managing the Testing Environment

Don't assume that mobile applications are simpler to test just because they are smaller than desktop applications or have fewer features. Testing mobile applications poses many unique challenges to testers, especially in terms of configuration management. Identifying and Acquiring Target Handsets The earlier you can decide on and get your hands on the target handsets, the better. Sometimes, this is as easy as going to the store and grabbing a new phone with a new service plan other times, it's...

Enabling USB Debugging on an Android Device

To enable USB debugging, from the Home screen of the Android device, select Menu, Settings, Applications, Development and enable the USB Debugging option. Different devices may have this option in different places. For instance, on the Archos 5 Internet tablet, it is found under Device Storage & USB connection, USB Connection Mode, and then choose Debug Bridge (ADB) to enable USB debugging. During long debugging sessions, your phone might often go to sleep. To prevent this from happening,...

Editing Project Resources

By default, the Android manifest file resource editor is opened when you create a new Android project. If you have clicked away from this screen to check out the various project files, simply double-click the AndroidManifest.xml file within your new project to return to the Android manifest file resource editor (see Figure 1.3). Editing an Android resource file in Eclipse. The Android manifest file is the central configuration file for an Android application. The editor organizes the manifest...

Launching Android Applications on a Handset

It's time to load your application onto a real handset. To do this, you need to plug a handset into your computer, using the USB data cable. To ensure that you debug using the correct settings, follow these steps 1. In Eclipse, choose Run, Debug Configurations. 2. Double-click DroidDebug Debug Configuration. 3. On the Target tab, set Deployment Target Selection Mode to Manual. You can always change it back to Automatic later, but choosing Manual will force you to choose whether to debug within...

Handling Different Screen Orientations

Android applications can run in landscape or portrait mode, depending on how the user tilts the handset screen. Besides internationalization, one of the most common situations in which applications might want to customize resources is to handle screen orientation changes. Adding a Custom Layout for Landscape Mode Thus far, you have been developing and testing the Been There, Done That application in portrait mode. Launch it now and change to landscape mode before launching the application....

Enabling Friend Requests on the Settings Screen

To add friend support to the Been There, Done That application, you need to update QuizSettingsActivity to allow the user to input friend email addresses. Specifically, you need to do the following Add a button to the settings screen to launch a new dialog. Implement the dialog to QuizSettingsActivity to allow the user to input a friend's email address. Add some networking code to communicate the friend request to the application server. You need to update the user interface of the Been There,...

Did you Know

A toast is a view that pops up in the foreground to display a message for a few seconds and then disappears. For example, you could add a Toast message to the onClick method of the Button_DOB, like this TODO Launch DatePickerDialog, Toast.LENGTH_LONG .show Figure 10.6 shows the resulting Toast message. The Spinner control is basically the Android platform's version of a drop-down list. The control looks much like a drop-down when closed see Figure 10.7, left , but when the Spinner control is...

Configuring Your Operating System for Device Debugging

To install and debug Android applications on hardware such as the T-Mobile G1, Motorola Droid, or Nexus One, you might need to configure your operating system to access the phone via USB. This is especially true of Windows machines. The Android SDK ships with drivers for some devices, and you can simply point the Device Manager at the directory where you installed the Android SDK and then plug in the phone via USB, and it will show up when you launch an application via Eclipse. You need to...

Naming Android Packages

You define the package within the Android manifest file in the lt manifest gt tag, using the package attribute, as follows If you use the Android project wizard in Eclipse to create a project, you must fill in the package name at that time. That package name is used in the default Android manifest file.

DDMS Dalvik Debug Monitor Service

Device debugging, 414 USB debugging, 413-414 EditText controls, 168 power settings, 363 ringtones, 356 Spinner controls, 173 TabHost control, 155 wallpaper, 356-357 conformance testing, 370 ConnectivityManager class, 261 contacting authors, 425 Contacts application, 37 Contacts content provider, 360 contains method, 177 containsKey method, 210 content providers Browser, 360 CallLog, 360 Contacts, 360 explained, 360-361 live folders, 361 MediaStore, 360 UserDictionary, 360 context menus, 138...

Performing Automated Testing

Collecting application information and building automated tests can help you build a better, more bulletproof application. The Android SDK provides a number of packages related to code diagnostics. Application diagnostics fall into two categories Logging application information for performance or usage statistics Automated test suites based on the JUnit framework At the beginning of this book, you learned how to leverage the built-in logging class Log android.util.Log to implement different...

Configuring Button Controls

Many of the typical attributes of TextView controls, such as textColor and textSize, are available for the Button text label. You need two simple Button controls for the settings screen one for launching the Password Dialog window and one for launching the DatePickerDialog. You configure these Button controls by giving each a unique identifier and setting the text attribute labels of each. You also set each Button control's layout_width and layout_height attributes to wrap_con-tent so that each...

Summary

In this hour, you've seen how different Android applications can be designed using three application components Context, Activity, and Intent. Each Android application comprises one or more activities. Top-level application functionality is accessible through the application context. Each activity has a special function and usually its own layout, or user interface. An activity is launched when the Android system matches an intent object with the most appropriate application activity, based on...

Handling Long Clicks with setOnLong ClickListener

A long-click is a special type of click available on the Android platform. Basically, a long-click event is when a user clicks on a control for about one second. This type of click is handled separately from a regular, short click. To handle long-clicks, you need to implement the View.OnLongClickListener class and pass it into the ImageButton control's setOnLongClickListener method. OnLongClickListener has one required method you must implement onLongClick . Here is a sample implementation of...

Configuration Management for Android

Developers must try to support the widest possible range of devices, without biting off more than they can chew in terms of maintenance and configuration management. The following are some factors to consider when determining target platforms What hardware features will the application require Does the application require a touch screen A hardware keyboard A directional pad Specific screen dimensions What software features will the application require Does the application support different...

Checking Network Status

The Android SDK provides utilities for gathering information about the current state of a network. This is useful for determining whether a network connection is available before trying to use a network resource. By validating network connectivity before attempting to make a connection, you can avoid many of the failure cases common in mobile device networking applications and provide your end users with a more pleasant user experience. Retrieving Network Status Information Programmatically...

Implementing Application Activities

To implement a base Activity class, you simply copy the source file called QuizSplashActivity.java. Then you create a new class file called QuizActivity. This class should look very simple for now In the project code for this chapter, and future chapters, you will see that there is only a single drawable resource directory named drawable. Whenever the Android system goes about picking a drawable resource, it only looks in this directory instead of the three default directories, drawable-ldpi,...

Quiz

True or False All Android applications can and should be enhanced using social features. 2. How does the Been There, Done That application create friend relationships A. By allowing the player to search the application server for friends he or she recognizes B. By allowing the player to input a friend's email address C. By launching the Contacts application and allowing the player to choose a contact D. By allowing the player to input a friend's phone number 3. True or False The Android SDK...

Initializing an Image Switcher Control

To initialize an ImageSwitcher control, you simply set its ViewFactory and then use one of the three methods to set the image. In this case, you use the setImageDrawable method, like so ImageSwitcher questionImageSwitcher ImageSwitcher questionImageSwitcher.setFactory new MyImageSwitcherFactory Drawable image Unfortunately, you cannot use the setImageURI method with a remote online URL with ImageSwitcher at this time. Instead, you need to perform a bit of extra work to download the image from...

Using the Application

The Application tab see Figure 5.2 contains application-wide settings, including the application label and icon, as well as information about application components such as activities, intent filters, and other application functionality, including configuration for service and content provider implementations. Java - Droidl AndroidManifest.xml - Eclipse Edit Run Navigate Search Project Refactor Win amp - - - s -- - egPl'i' Defines general information about the AndroidManifestxml Package...

Uploading Player Data with the Http Get Method

The player data is submitted to the application server by using the HTTP GET method via the HttpGet class. Because you are posting form query variables, you want to use the URLEncodedUtils utility with a List container of BasicNameValuePair objects to assist with creating the final URL for the request. Finally, the whole network operation must be wrapped inside the AsyncTask object so that the user interface can continue to respond while the network request is being handled. Creating an...

Working with Application Resources

Chippy Revenge

Application resources are created and stored within the Android project files under the res directory. Using a well-defined but flexible directory structure, resources are organized, defined, and compiled with the application package. Application resources are not shared with the rest of the Android system. Defining application data as resources is a good programming practice. Grouping application resources together and compiling them into the application package has the following benefits Code...

Managing Application Permissions

The Android platform is built on a Linux kernel and leverages its built-in system security as part of the Android security model. Each Android application exists in its own virtual machine and operates within its own Linux user account see Figure 5.6 . Applications that want access to shared or privileged resources on the handset must declare those specific permissions in the Android manifest file. This security mechanism ensures that no application can change its behavior on-the-fly or perform...