Replacing the Native Dialer

Replacing the native dialer application involves two steps 1. Intercepting Intents that are currently serviced by the native dialer. 2. Initiating, and optionally managing, outgoing calls. The native dialer application currently responds to Intent actions corresponding to a user's pressing the hardware call button, asking to view data using the tel schema, or making a request to dial a number using the tel schema. To intercept these requests include lt intent-filter gt tags on your new Activity...

Emergency Responder SMS Example

In this example, you'll create an SMS application that turns an Android phone into an emergency response beacon. Once finished, the next time you're in unfortunate proximity to an alien invasion or find yourself in a robot-uprising scenario, you can set your phone to automatically respond to your friends' and family members' pleas for a status update with a friendly message or a desperate cry for help . To make things easier for your would-be saviors, you'll use location-based services to tell...

Types of Android Applications

Most of the applications you create in Android will fall into one of the following categories > Foreground An application that's useful only when it's in the foreground and is effectively suspended when it's not visible. Games and map mashups are common examples. > Background An application with limited interaction that, apart from when being configured, spends most of its lifetime hidden. Examples include call screening applications and SMS auto-responders. > Intermittent Expects some...

Playing Sound with Audio Track

Use the AudioTrack class to play raw audio directly into the hardware buffers. Create a new Audio Track object, specifying the streaming mode, frequency, channel configuration, and the audio encoding type and length of the audio to play back. AudioTrack audioTrack new Because this is raw audio, there is no meta-data associated with the recorded files, so it's important to correctly set the audio data properties to the same values as those used when recording the file. When your Audio Track is...

Introducing Itemized Overlays and Overlay Items

Overlayitems are used to supply simple maker functionality to your Map Views via the ItemizedOverlay class. itemizedOverlays provide a convenient shortcut for adding markers to a map, letting you assign a marker image and associated text to a particular geographical position. The ItemizedOverlay instance handles the drawing, placement, click handling, focus control, and layout optimization of each Overlayitem marker for you. To add an itemizedOverlay marker layer to your map, start by creating...

Native Android Actions

Native Android applications also use Intents to launch Activities and sub-Activities. The following non-comprehensive list shows some of the native actions available as static string constants in the Intent class. When creating implicit Intents you can use these actions, called Activity Intents, to start Activities and sub-Activities within your own applications. Later you will be introduced to Intent Filters and you'll learn how to register your own Activities as handlers for these actions....

Using The Manifest Editor

The ADT plug-in includes a visual Manifest Editor so you don't have to manipulate the underlying XML directly. To use the Manifest Editor in Eclipse, right-click the AndroidManifest.xml file in your project folder and select Open With O Android Manifest Editor. This presents the Android Manifest Overview screen, as shown in Figure 3-1. This screen gives you a high-level view of your application structure, enabling you to set your application version information and root level manifest nodes,...

Native Preference Controls

Android includes several preference controls to build your Preference Screens > CheckBoxPreference A standard preference checkbox control. Used to set preferences to true or false. > EditTextPreference Allows users to enter a string value as a preference. Selecting the preference text will display a text entry dialog. > ListPreference The preference equivalent of a spinner. Selecting this preference will display a dialog box containing a list of values from which to select. You can...

Creating a Map Based Activity

To use maps in your applications you need to extend MapActivity. The layout for the new class must then include a MapView to display a Google Maps interface element. The Android maps library is not a standard Android package as an optional API, it must be explicitly included in the application manifest before it can be used. Add the library to your manifest using a uses-library tag within the application node, as shown in the following XML snippet lt uses-library The maps package as described...

Externalizing Resources

No matter what your development environment, it's always good practice to keep non-code resources like images and string constants external to your code. Android supports the externalization of resources ranging from simple values such as strings and colors to more complex resources like images Drawables , animations, and themes. Perhaps the most powerful externalizable resources are layouts. Prepared for ASHLEE KABAT, email akabat spam.la Order number 56760408 This PDF is for the purchaser's...

Using the Contacts Provider

Access to the contact manager is particularly useful on a communications device. Android does the right thing by exposing all the information available from the contacts database to any application granted the READ_CONTACTS permission. Android 2.0 API level 5 introduced the ContactsContract class, which superceded the Contacts class that had previously been used to store and manage the contacts stored on the device. The new contact Content Provider extends the scope of contacts management in...

Creating a Compass View Example

Android Drawcircle Drawline Example

In the following example you'll create a new Compass View by extending the View class. This View will display a traditional compass rose to indicate a heading orientation. When complete, it should appear as in Figure 4-2. A compass is an example of a UI control that requires a radically different visual display from the Text Views and Buttons available in the SDK toolbox, making it an excellent candidate for building from scratch. In Chapter 14 you'll use this Compass View and the device's...

Listening for Incoming SMS Messages

When a new SMS message is received by the device, a new broadcast Intent is fired with the android.provider.Telephony.SMS_RECEIVED action. Note that this is a string literal, the SDK currently doesn't include a reference to this string, so you must specify it explicitly when using it in your applications. The SMS received action string is hidden therefore unsupported . As such it is subject to change at any future platform release. As always, be very cautious when using unsupported platform...

Bluetooth Data Transfer Example

The following example uses the Android Bluetooth APIs to construct a simple peer-to-peer messaging system that works between two paired Bluetooth devices. Unfortunately the Android emulator can't currently be used to test Bluetooth functionality. In order to test this application you will need to have two physical devices. 1. Start by creating a new BluetoothTexting project featuring a BluetoothTexting Activity. Modify the manifest to include Bluetooth and bluetooth_admin permissions. lt xml...

Fundamental Android Ui Design

User interface UI design, user experience UX , human computer interaction HCI , and usability are huge topics that aren't covered in great depth in this book. Nonetheless, it's important that you get them right when creating your user interfaces. Android introduces some new terminology for familiar programming metaphors that will be explored in detail in the following sections gt Views Views are the base class for all visual interface elements commonly known as controls or widgets . All UI...

Hardware Imposed Design Considerations

Small and portable, mobile devices offer exciting opportunities for software development. Their limited screen size and reduced memory, storage, and processor power are far less exciting, and instead present some unique challenges. Compared to desktop or notebook computers, mobile devices have relatively High costs associated with data transfer Slow data transfer rates with high latency Each new generation of phones improves many of these restrictions. In particular, newer phones have...

Understanding Application Priority And Process States

The order in which processes are killed to reclaim resources is determined by the priority of the hosted applications. An application's priority is equal to its highest-priority component. If two applications have the same priority, the process that has been at a lower priority longest will be killed first. Process priority is also affected by interprocess dependencies if an application has a dependency on a Service or Content Provider supplied by a second application, the secondary application...

Using Internet Resources

Android offers several ways to leverage Internet resources. At one extreme you can use a WebView to include a WebKit-based browser View within an Activity. At the other extreme you can use client-side APIs such as Google's GData APIs to interact directly with server processes. Somewhere in between, you can process remote XML feeds to extract and process data using a Java-based XML parser such as sax or the more efficient XmlPullParser. Detailed instructions for parsing XML and interacting with...