Why Android

Google's Android mobile phone software platform may be the next big opportunity for application software developers. Google announced the Open Handset Alliance and the Android platform in November of 2007, releasing the first beta version of the Android Software Development Kit (SDK) at the same time. Within a matter of a few months, over 1 million people had downloaded versions of the SDK from Google's website. In the United States, T-Mobile announced the G1 Android mobile phone in October of...

The Model

The Model is the guts of your application what it actually does. It might be, for instance, the database of tunes on your device and the code for playing them. It might be your list of contacts and the code that places phone calls or sends IMs to them. Figure 10-1. Model-View-Controller concept While a particular application's View and Controller will necessarily reflect the Model they manipulate, a single Model might be used by several different applications. Think, for instance, of an MP3...

Advanced Wiring Focus and Threading

As demonstrated in Example 10-9 and Listening for Touch Events on page 173, MotionEvents are delivered to the widget whose bounding rectangle contains the coordinates of the touch that generated them. It isn't quite so obvious how to determine which widget should receive a KeyEvent. In order to do this, the Android UI framework, like most other UI frameworks, supports the concept of selection, or focus. In order to accept focus, a widget's focusable attribute must be set to true. This can be...

The Open Handset Alliance

Google and 33 other companies announced the formation of the Open Handset Alliance on November 5, 2007. According to the joint press release from that day This alliance shares a common goal of fostering innovation on mobile devices and giving consumers a far better user experience than much of what is available on today's mobile platforms. By providing developers a new level of openness that enables them to work more collaboratively, Android will accelerate the pace at which new and compelling...

Table of Contents

Development Kit Walk-Through 1. Getting to Know The Android Execution Environment 5 Components of an Android Application 6 2. Setting Up Your Android Development Setting Up Your Development Environment 13 Creating an Android Development Environment 14 Starting a New Android Application HelloWorld 18 3. Using the Android Development Environment for Real Applications 27 MicroJobs This Book's Main Sample Application 27 Android and Social Networking 27 Downloading the MJAndroid Code 30...

Rolling Your Own Widgets

As mentioned earlier, widget is a just convenient term for a subclass of android.view.View, typically for a leaf node in the view tree. Many views are just containers for other views and are used for layout we don't consider them widgets, because they don't directly interact with the user, handle events, etc. So the term widget, although informal, is useful for discussing the workhorse parts of the user interface that have the information and the behavior users care about. You can accomplish a...

Java Errors

1 package corr oreilly. debug 6 public class DefcugTest extends Activity ** Called when the activity is first created. ' Override public void onCreate(Bundle savedlnstanceState) super.onCreate(savedlnstanceState) setContentView(R.layout.main) R cannot be resolved Press 'F2' for focus the syntax of the language they are editing, and in this case, the error flag is telling us there's a problem with this part of the code. If we use the mouse to hover over the R, we get a pop up that gives us more...

Basic Structure of the Micro JobsDatabase Class

In our example, the MicroJobsDatabase.java file completely encapsulates all of the SQL logic necessary to work with the database. All of the other Java classes in the MicroJobs application work with standard Java classes or Cursors and are unaware of how the data is actually stored. This is good programming practice and should be emulated in all of your Android applications that use databases. Before we delve too deeply into the guts of creating a database and selecting data from it, it's...

Oreilly

This in-depth hook provides the concepts and code you need to start building smartphone applications with the Android programming environment, the most popular open source platform available for mobile app development. Andruicl Application Development introduces you to this environment including the operating system and SDK and provides working examples with thorough explanations to demonstrate Android's architectural features and APIs. Write Android applications that take advantage of any core...

Inserting data into the database

The SQL INSERT statement is used whenever you want to insert data into an SQL database. The INSERT statement maps to the create operation of the CRUD methodology. In the MJAndroid application, the user can add jobs to the list by clicking on the Add Job menu item when looking at the Jobs list. The user can then fill out a form to input the employer, job title, and description. After the user clicks on the Add Job button on the form, the following line of code is executed db.addJob(employer.id,...

Android Service Lifecycle

The lifecycle for a service is similar to that for an activity, but different in a few important details Services can be started when a client calls the Context.startService(Intent) method. If the service isn't already running, Android starts it and calls its onCreate method followed by the onStart method. If the service is already running, its onStart method is invoked again with the new intent. So it's quite possible and normal for a service's onStart method to be called repeatedly in a...

Android Activity Lifecycle

Android is designed around the unique requirements of mobile applications. In particular, Android recognizes that resources (memory and battery, for example) are limited on most mobile devices, and provides mechanisms to conserve those resources. The mechanisms are evident in the Android Activity Lifecycle, which defines the states or events that an activity goes through from the time it is created until it finishes running. The lifecycle is shown diagrammatically in Figure 1-1. Your activity...

Android and Social Networking

One of the great promises of Android mobile phones is their ability to run applications that enhance opportunities for social networking between users. This promise echoes the reality of the Internet. The first generation of Internet applications were about user access to information, and many of those applications have been very popular. The second wave of Internet applications has been about connecting users to each other. Applications such as Facebook, YouTube, and many others enhance our...

Listening for Touch Events

Modifying the demo application to handle taps is just a matter of adding a tap handler. The code in Example 10-8 extends the demo application to place a cyan dot in the DotView at the point at which the screen is tapped. In the previous example, the code would be added at the beginning of the onCreate function right after the call to its parent method. Notice that, because the code that displays the X and Y coordinates of the most recently added dot is wired only to the Model, it continues to...

Assembling a Graphical Interface

The Android UI framework provides both a complete set of drawing tools with which to build a UI and a rich collection of prebuilt components based on these tools. As we will see in Chapter 12, the framework graphics tools provide plenty of support for applications that need to create their own controls or render special views. On the other hand, many applications may work very well using only canned widgets from the toolkit. In fact, as we saw in Chapter 9, the MapActivity and MyLocationOverlay...

Android GUI Architecture

The Android environment adds yet another Graphical User Interface GUI toolkit to the Java ecosphere, joining AWT, Swing, SWT, and J2ME leaving aside the web UI toolkits . If you've worked with any of these, the Android framework will look familiar. Like them, it is single-threaded, event-driven, and built on a library of nestable components. The Android UI framework is, like the other UI frameworks, organized around the common Model-View-Controller pattern illustrated in Figure 10-1. It...

Getting a Result via Inter Process Communication

This section modifies the Hello World application from an earlier chapter to show how Android can make separate Activity objects in separate programs seem of-a-piece. This version uses one Activity to enable the user to choose which greeting to put on the screen in another Activity. A copy of the data put into the Intent object in the previous section ends up in an Intent object in the HelloWorldActivity Activity. To enable a client to find the Intent, the server assigns it a label called an...

Safari Books Online

When you see a Safari Books Online icon on the cover of your favorite technology book, that means the book is available online through the O'Reilly Network Safari Bookshelf. Safari offers a solution that's better than e-books. It's a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http my.safaribooksonline.com.

Delete data

A user who pulls up a list of notes from the NotesList class can choose the Delete option on the context menu to run the following method Override public boolean onContextItemSelected MenuItem item AdapterView.AdapterContextMenuInfo info info AdapterView.AdapterContextMenuInfo item.getMenuInfo switch item.getItemId case MENU_ITEM_DELETE Delete the note that the context menu is for Uri noteUri info.id getContentResolver .delete noteUri, null, null return true Here are some of the highlights of...

Index

Adb shell prompt and, 73 defining colors, 49 backslashes , escaping characters, 104 amp ampersand, running adb logcat, 73 2D graphics, 221-255 2G second generation digital cellulars, 305 3D graphics, 221-255 matrix transformations and, 231 3rd Generation Partnership Program 3GPP , 307 4G fourth generation digital cellulars , 307 Abbreviated Dialing Numbers see ADNs AbsoluteLayout, 215-216 ACCESS_FINE_LOCATION permission, 45 ACCESS_LOCATION_EXTRA_COMMAND S permission, 45 ACCESS_MOCK_LOCATION...

Android Debug Bridge adb

Android comes with a specialized command-line debug utility called adb. It lets you control a device or emulator from your host, offering the kind of remote terminal or remote shell service that embedded programmers have come to expect when working with their target systems. Invoke the adb client from a command prompt on the host Start Run cmd.exe on Windows, or open a terminal window on Linux or OS X . The client talks to an adb server that runs in background on the host and processes...

Reading Data from the Database

There are many ways to read data from an SQL database, but they all come down to a basic sequence of operations 1. Create an SQL statement that describes the data that you need to retrieve. 2. Execute that statement against the database. 3. Map the resulting SQL data into data structures that the language you're working in can understand. This process can be very complex in the case of object-relational mapping software, or relatively simple when writing the queries directly into your...

Location and Mapping

Ever since mobile phones started incorporating devices that made them aware of their geographic locations, developers have foreseen a new era of location-based applications. Location awareness improves many applications and makes possible totally new applications. If your application is looking up restaurants, it's clearly better if you can restrict your search to the area around you. It's even better if you can see a map of the restaurants' locations, and perhaps be able to look up driving or...

Logcat

Granted, the errors we debugged in the last section were pretty straightforward no different from debugging in any other environment. But most applications are not as simple as DebugTest, and many problems are much harder to isolate and solve. Android provides a general-purpose logging facility that can help with many of those more difficult problems. As mentioned before, there's a logcat pane on the Debug perspective it's also in the DDMS perspective, which we'll talk about in the next section...

Tab Host

Tabhost Image Android

Most modern Uls provide an interface element that lets the user flip through many pages of information quickly using tabs, with each screen of information available when its tab is pressed. Android's option is the TabHost View. Figures 11-7 through 11-10 show how it operates. Android enables the developer to choose between three different approaches for setting the tab's content. The developer can Set the content of a tab to an Intent. Figures 11-7 and 11-9 use this method. Use a...

Initialization Parameters in Android Manifestxml

As Chapter 3 explained, we told Android to launch Microjobs.java as the first Activity for MJAndroid. We defined that on the Application tab of the AndroidManifest.xml editor. The first part of the XML code that results from that choice is shown here lt xml version 1.0 encoding utf-8 gt lt manifest android versionCode 1 lt uses-permission gt lt uses-permission android name gt lt uses-permission gt lt uses-permission gt lt uses-permission gt application lt uses-library gt lt activity android...

Inter Process Communication and AIDL in the androidinternaltelephony Package

Many of the internal packages use the remote methods feature discussed in Remote Methods and AIDL on page 265. The TelephonyManager and PhoneStateListener classes rely on this to communicate with PhoneApp. The ServiceManager class is also used. Figure 15-1. Layers of telephony packages To marshall data for remote methods, the package includes AIDL files. For instance, the following AIDL comes from IPhoneStateListener.aidl oneway interface IPhoneStateListener void onServiceStateChanged in...

More Initialization of Micro Jobsjava

The previous section was a rather long digression into XML Layout files, but as you can see, that is where a lot of the initialization of the application's user interface takes place where views are defined, named, and given attributes where the screen is layed out and where hints are given to the layout manager describing the way we would like the screen to look. Let's get back to the Java code that brings up the application, starting where we left off in MicroJobs.java db new...

The androidinternaltelephonygsm Package

Many of the classes and interfaces in the previous section are typical of a Java API that can have multiple implementations. The implementations of the API defined in the telephony.internal package correspond to a library used in the RIL. To better understand this API, we will look at one implementation here that supports GSM. Thus, this section delves further into the telephony internals of Android, looking especially at how the interfaces and abstract base classes are implemented and...

Shadows Gradients and Filters

PathEffect, MaskFilter, ColorFilter, Shader, and ShadowLayer are all attributes of Paint. Anything drawn with Paint can be drawn under the influence of one or more of these transformations. The top several widgets in Figure 12-5 give examples of some of these effects. Widgets 1 and 2 demonstrate shadows. Shadows are currently controlled by the setShadowLayer method. The arguments, a blur radius and X and Y displacements, control the apparent distance and position of the light source that...

Components of an Android Application

Lifecycle Activity Android

Your Android applications will be built from four basic component types that are defined by the Android architecture These are comparable to standalone utilities on desktop systems, such as office applications. Activities are pieces of executable code that come and go in time, instantiated by either the user or the operating system and running as long as they are needed. They can interact with the user and request data or services from other activities or services via queries or Intents...

Layout

Most of the heavy lifting in the Android framework layout mechanism is implemented by container views. A container view is one that contains other views. It is an internal node in the view tree and subclasses of ViewGroup which, in turn, subclasses View . The framework toolkit provides a variety of sophisticated container views that provide powerful and adaptable strategies for arranging a screen. AbsoluteLayout see AbsoluteLayout on page 215 , LinearLayout see LinearLayout on page 209 , and...

Implementing a content provider

The Android SDK contains a document that describes nine steps to creating a content provider. In summary, they are 1. Extend the ContentProvider class. 2. Define the CONTENT_URI for your content provider. 3. Create the data storage for your content. 4. Create the column names for communication with clients. 5. Define the process by which binary data is returned to the client. 6. Declare public static Strings that clients use to specify columns. 7. Implement the CRUD methods of a Cursor to...

First Steps Building and Running the Micro Jobs Application

So now that we know a bit about which files are located in which folders, what happens when we ask Android to run the MJAndroid application And for that matter, how do we ask Android to run the application Let's take a closer look at the Android SDK environment and the views and commands available to us for running and debugging any application. A Very Short Tour of the Android SDK Eclipse IDE The Android SDK provides three perspectives for working with Android projects and applications. If...

Android Interface Definition Language

To communicate from one process to another, data stored in memory has to be moved across process boundaries. That means the data has to be marshalled packaged for transport and unmarshalled put into the right member variables after the data has been moved across the process boundary. Some Android documentation uses the word flattened, with the connotation of taking a data stored in several objects and turning it into a flat array of bytes that can be sent between processes. Java's basic types,...

Inter Process Communication

Android is designed to host a variety of applications and to maximize user choice. The platform is intended to eliminate the duplication of functionality in different applications, to allow functionality to be discovered and invoked on the fly, and to let users replace applications with others that offer similar functionality. Applications must have as few dependencies as possible, and must be able to contract out operations to other applications that may change at the user's discretion....

Listening for Key Events

Handling keystroke input across multiple platforms can be very tricky. Some devices have many more keys than others, some require triple-tapping for character input, and so on. This is a great example of something that should be left to the framework EditText or one of its subclasses whenever possible. To extend a widget's KeyEvent handling, use the View method setOnKeyListener to install an OnKeyListener. The listener will be called with multiple KeyEvents for each user keystroke, one for each...

Scroll View

A ScrollView is a container for another View that lets the user scroll that View vertically a scrollbar is optional . A ScrollView often contains a LinearLayout, which in turn contains the Views that make up the form. Don't confuse ScrollView with ListView. Both Views present the user with a scrollable set of Views, but the ListView is designed to display a set of similar things, such as the cheeses in the previous section. The ScrollView, on the other hand, allows an arbitrary View to scroll...

Bling

Stroke Android Drawrect Gradient

The Android UI framework is a lot more than a just an intelligent, well-put-together GUI toolkit. When it takes off its glasses and shakes out its hair, it can be downright sexy The tools mentioned here certainly do not make an exhaustive catalog. They might get you started, though, on the path to making your application Filthy Rich. Several of the techniques discussed in this section are close to the edges of the Android landscape. As such, they are less well established the documentation is...

Exploring Android Telephony Internals

A lot of code lies between creating an ACTION_CALL Intent object and dialing a call. Here we will go even deeper into Android's telephony system to see what Android is telling the mobile radio, and match that up with what we have done in the example application earlier in this chapter. To see how, and when, Android actually commands the hardware to dial a number, we can use Android's logging system. To access the log buffer for information about the traffic between Android software and the...

Check Boxes Radio Buttons and Spinners

Spinner Android Example

The Views we present in this section are probably familiar to you from other user interfaces. Their purpose is to allow the user to choose from multiple options. CheckBoxes are typically used when you want to offer multiple selections with a yes no or true false choice for each. RadioButtons are used when only one choice is allowed at a time. Figure 11-3. CheckBox, RadioButtons, and Spinner Spinners are similar to combo boxes in some frameworks. A combo box typically displays the currently...

Persistent Data Storage SQLite Databases and Content Providers

To accomplish many of the activities offered by modern mobile phones, such as tracking contacts, events, and tasks, the operating system and applications must be adept at storing and keeping track of large quantities of data. Most of this data is structured like a spreadsheet, in the form of rows and columns. Each Android application is like an island unto itself, in that each application is only allowed to read and write data that it has created, but sharing data across application boundaries...

DDMS Dalvik Debug Monitor Service

Installing the Android Software Development Kit adds DDMS to the Eclipse integrated development environment, providing a window-oriented interface to Android-specific debug information on the target. The most frequently used perspectives are displayed in the upper-right corner of the Eclipse window. If there's a DDMS button there, you can just click on it to switch to DDMS. If not, in that same area there is a little window symbol with a sign in its upper-right corner. Clicking on this window...

Limitations on What Applications Can Do with the Phone

Some readers may be disappointed to see that the android.telephony package limits their access to getting information, and does not provide direct control over the dialer or the state of a call. There are good reasons for this. Essentially, providing a low-level telephony API that can be shared among multiple applications is perilous. A mobile handset is a state machine that keeps track of the mobile radio reports, provides audible call state indications to the user, and enables the user to...

Text View and Edit Text

A TextView, as shown in the line This is some text in Figure 11-1, is just what you'd expect a place to display a text string. The vanilla TextView is for display only, whereas EditText is a predefined subclass of TextView that includes rich editing capabilities. Each TextView has the attributes you'd expect of such a component you can change its height, width, font, text color, background color, and so forth. TextViews also have some useful unique attributes If set true , finds URLs in the...

Adapters and Adapter Views

Adapters and AdapterViews are an important and useful basis for several of the views discussed in the rest of this chapter. Using extensions to these classes, you can address an extremely wide variety of situations. The AdapterView is a generic, list-oriented view of data. Any collection of data objects that can be ordered in some relatively stable way can be displayed through an AdapterView. An AdapterView is always associated with an Adapter, which acts as the bridge between it and the...

OpenGL Graphics

The Android platform supports OpenGL graphics in roughly the same way that a silk hat supports rabbits. Although this is certainly among the most exciting technologies in Android, it is definitely at the edge of the map. It also appears that just before the final beta release, the interface underwent major changes. Much of the code and many of the suggestions found on the Web are obsolete and no longer work. The API V1_r2 release is an implementation of OpenGL ES 1.0 and much of ES 1.1. It is,...

Listening to the Model

The Android UI framework uses the handler installation pattern pervasively. Although our earlier examples were all Buttons, many other Android widgets define listeners. The View class defines several events and listeners that are ubiquitous, and which we will explore in further detail later in this chapter. Other classes, however, define other specialized types of events and provide handlers for those events that are meaningful only for those classes. This is a standard idiom that allows...

Pausing and Resuming a Map Activity

Mobile applications have unique requirements, due mostly to the constrained resources available to execute applications. For now let's focus on MapActivities and talk about a way we can help save battery power. The good news is that Android makes it pretty easy. In a mobile environment, battery life is everything, and if we're not the application that is currently being displayed, we want to do everything we can to minimize the power we consume. You recall from the discussion of the Android...

Connecting to a Location Provider and Getting Location Updates

Let's start with an Activity that just connects with the GPS LocationProvider and gets and displays our current location no updates . The procedure is pretty straightforward package com.microjobsinc.dloc import android.app.Activity import android.content.Context import android.location.Location import android.location.LocationManager import android.os.Bundle import android.widget.TextView public class Main extends Activity Called when the activity is first created. Override public void onCreate...

Android Telephony Internals

The rest of this chapter covers telephony-related classes in the internals package that only PhoneApp uses, android.internal.telephony. This package is layered over an implementation of telephony internals for a particular telephony technology, such as GSM or CDMA. That layer, in turn, communicates with a Radio Interface Layer RIL that is implemented as a daemon in Android. Figure 15-1 shows the architecture of the Android telephony system. PhoneApp supports an Intent that enables other...

Relative Layout

We've used RelativeLayout, often in combination with LinearLayout, throughout the MJAndroid application. The advantage of RelativeLayout is that you can express the Figure 11-16. Same AbsoluteLayout in landscape mode relative positioning of the Views in the screen, and the layout manager will do its best to fit them all on the screen in the proper relations. An example follows lt xml version l.0 encoding utf-8 gt lt TextView android id id txtTextl android text Textl android gravity top gt lt...

Using DDMS to update location

We talked a lot about DDMS the Dalvik Debug Monitor Service in Chapter 5, but two features are related to location updates. The Emulator Control pane of the DDMS screen provides several ways of controlling the running emulator. After switching to the DDMS perspective click on DDMS in the upper right of the Eclipse window , you should see the Emulator Control pane in the middle left of the DDMS window Figure 9-1 . You will probably have to scroll down in that pane to see the controls related to...

Intents Simple Low Overhead IPC

The Android system uses Intent objects to enable applications to specify an Activity or Service. Intent objects also deliver data from one application to another, providing a simple and convenient form of IPC. The Intent class, the Activity class, and Android's Intent-based inter-process communication solve one of the user interface problems of smartphone platforms that support multiple separate applications they feel like a collection of separate programs. You don't have the simplicity of...

Map View and MyLocation Overlay Initialization

At startup, and when we select Current Location from the Spinner, we want to display a map of our current location, and we want that map to track us as we move around. For this map we will use the MyLocationOverlay class. When we select a specific location from the Spinner, we want to display a map of that location, turn off location updates, and not track movement. Let's look again at the code in MicroJobs.java that initializes the MapView and the MyLocationOverlay that tracks our current...

Getting a Signing Certificate While Debugging

When you're creating and debugging your application that uses a MapView, or when you're running a demo application like MJAndroid, you still need a valid Map API Key to get map tiles from Google Maps, and you need the fingerprint of your debug signing certificate to obtain a Map API Key. You can't just use the apiKey that we have coded into the MJAndroid source files, because it is tied to the signing certificate that was generated by our debug environment. Your debug environment will generate...

The Map View and Map Activity

This book's MJAndroid application needs to be able to add overlays that show the locations for jobs in the area. So instead of using the Google Maps application, we will use a MapView, which we can overlay with as many graphics as we want. You can have only one MapView per Activity, however, and your activity has to extend MapActivity. As you'll see, that's a small price to pay for all the functionality that comes for free. There are a couple of unique prerequisites for using MapViews in your...

Gallery and Grid View

The Gallery ViewGroup Figure 11-4 displays multiple items in a horizontally scrolling list. The currently selected item is locked in the center of the screen. Any items that approach the edge of the screen begin to fade, giving the user the impression that there may be more items around the corner. The user can scroll horizontally through the items within the gallery. This ViewGroup is useful when you want to present a large set of possible choices to the user without using too much screen real...

Drawables

A Drawable is an object that knows how to render itself on a Canvas. Because a Drawable has complete control during rendering, even a very complex rendering process can be encapsulated in a way that makes it fairly easy to use. Examples 12-7 and 12-8 show the changes necessary to implement the previous example, Figure 12-3, using a Drawable. The code that draws the red and green text has been refactored into a HelloAndroidTextDrawable class, used in rendering by the widget's onDraw method....

Example Determining the State of a Call

This section shows how to track the state of a phone call. It adds some of the classes described in the previous section to the application shown in Creating an Example Application to Run the call Method on page 278, which finds and uses PhoneApp to start and control a phone call. Here, in addition to starting a phone call and letting PhoneApp control it, the application gets some information about the call as it is happening. In order to get this information, we need to extend the...

Canvas Drawing

Now that we've explored how widgets allocate the space on the screen in which they draw themselves, we can turn to coding some widgets that actually do some drawing. The Android framework handles drawing in a way that should be familiar, now that you've read about measurement and arrangement. When some part of the application determines that the current screen drawing is stale because some state has changed, it calls the View method invalidate. This call causes a redraw event to be added to the...

Linkify Demo

This technique should work for demos that you can't find with the previous method. If the ApiDemos application doesn't store information about the demo in res strings.xml, it gets its information directly from AndroidManifest.xml and so will we. 1. After starting the ApiDemos application, find the particular demo through clicking on the menu, and remember the path you took through the menu system. In this case, you click on Text and then Linkify. 2. Open the AndroidManifest.xml file and search...

Brief Tour of the MJAndroid Code

MJAndroid is a relatively simple application, despite the capabilities it gives its users. This section will give you an overview of the code and resource modules, tell you where they are located in the directory structure, and provide a glimpse of what each component does. You may want to refer to this section in the future when you're trying to find example code for a particular function and want to locate it in the MJAndroid code tree. MJAndroid uses a directory structure that is derived...

Downloading the MJAndroid Code

The MJAndroid application source code and project files are available from the O'Reilly website, at To download it to your development system, use a browser to navigate to the link given, and select Download MJAndroid. Your operating system Windows, Linux, or OS X will ask you to confirm that you want the download to happen, and ask you where to put the downloaded files. It doesn't matter where you put the downloaded, compressed files, but you want to extract the uncompressed files into the...

Adding Data to an Instance of an Intent

So far, our instance of the Intent class has enough information to tell the Android system we want to start a phone call, but not enough to tell it what number to call. After creating the Intent instance with the information that means we want to call a number, in the next line we will add to it the number to call Two things happen on this line of code an instance of a Uri is created, and we use that instance as an argument to the setData method of the Intent class. Step over this line of code,...

Adding Your Own Examples to Api Demos

The ApiDemos application is a handy sandbox for your own testing, and adding a new menu entry and Activity to it is quite easy. But remember that whenever you upgrade your API, all of your changes will be lost. Don't add code to the ApiDemo that you might want to save after an upgrade. It really is just a sandbox for quick tests. With that caveat in mind, this section shows you how to add a new menu and screen to the ApiDemos application. We'll do that by adding a new ToastTest Activity with a...

Android IPC Compared with Java Native Interface JNI

Remote procedure calls RPC using Android's inter-process communications largely replace the use of the Java Native Interface JNI in Android. In almost all cases, a remote procedure call is efficient enough to make it a superior alternative to loading a library especially one that dynamically allocates a significant amount of memory into the Java virtual machine's address space. And if a process exposing an RPC interface fails, it is less likely to bring down the Android UI with it. Android...

Animation

The Android UI toolkit offers several different animation tools. Transition animations which the Google documentation calls tweened animations are subclasses of android.view.animation.Animation RotateAnimation, TranslateAnimation, ScaleAnimation, etc. These animations are used as transitions between pairs of views. A second type of animation, subclasses of android.graphics.drawable.Animation Drawable, can be put into the background of any widget to provide a wide variety of effects. Finally,...

The androidinternaltelephony Package

This package contains the classes and interfaces PhoneApp uses to provide services to other applications that want to start phone calls, and classes that define an API to the RIL. PhoneApp, like all parts of Android, is theoretically replaceable. If your application needs to modify the classes used by PhoneApp, your application will probably have to replace or modify PhoneApp, and should provide the same services to other applications, using the classes in this package. The description of these...