Zipalign v 4 your project nameunalignedapk your project nameapk

The -v flag turns on verbose output (optional). 4 is the byte-alignment (don't use anything other than 4). The first file argument is your signed .apk (the input) and the second file is the destination .apk file (the output). If you're overriding an existing .apk, add the -f flag. Caution Your input .apk must be signed with your private key before you optimize the package with zipalign. If you sign it after using zipalign, it will undo the alignment. For more information, read about the...

Application Fundamentals

Android applications are written in the Java programming language. The compiled Java code along with any data and resource files required by the application is bundled by the aapt tool into an Android package, an archive file marked by an . apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices it's the file users download to their devices. All the code in a single .apk file is considered to be one application. In many ways, each Android...

Building Your Application

There are two ways to build your application one for testing debugging your application debug mode and one for building your final package for release release mode. As described in the previous section, your application must be signed before it can be installed on an emulator or device. Whether you're building in debug mode or release mode, you need to use the Ant tool to compile and build your project. This will create the .apk file that is installed onto the emulator or device. When you build...

Using dmtracedump

The Android SDK includes dmtracedump, a tool that gives you an alternate way of generating graphical call-stack diagrams from trace log files. The tool uses the Graphviz Dot utility to create the graphical output, so you need to install Graphviz before running dmtracedump. The dmtracedump tool generates the call stack data as a tree diagram, with each call represented as a node. It shows call flow (from parent node to child nodes) using arrows. The diagram below shows an example of dmtracedump...

Android 15 is a basic Android platform Do you wish to create a custom hardware profile [no

If you want to set custom hardware emulation options for the AVD, enter yes and set values as needed. If you want to use the default hardware emulation options for the AVD, just press the return key (the default is no). The android tool creates the AVD with name and system image mapping you requested, with the options you specified. If you are creating an AVD whose target is an SDK add-on, the android tool does not allow you to set hardware emulation options. It assumes that the provider of the...

Hello Relative Layout

A RelativeLayout is a ViewGroup that allows you to layout child elements in positions relative to the parent or siblings elements. 1. Start a new project Activity called HelloRelativeLayout. 2. Open the layout file. Make it like so < xml version 1.0 encoding utf-8 > < RelativeLayout android layout height fill parent> layout width fill parent layout height wrap content layout width fill parent layout height wrap content background layout below id label > layout width wrap content...

Using intent matching

Intents are matched against intent filters not only to discover a target component to activate, but also to discover something about the set of components on the device. For example, the Android system populates the application launcher, the top-level screen that shows the applications that are available for the user to launch, by finding all the activities with intent filters that specify the action and category (as illustrated in the previous section). It then displays the icons and labels of...

Application Components

A central feature of Android is that one application can make use of elements of other applications (provided those applications permit it). For example, if your application needs to display a scrolling list of images and another application has developed a suitable scroller and made it available to others, you can call upon that scroller to do the work, rather than develop your own. Your application doesn't incorporate the code of the other application or link to it. Rather, it simply starts...

Color paletteStep by step

Create the basic shape using a tool like Adobe Illustrator. 2- r 120 g 120 b 120 2. Import the shape into a tool like Adobe Photoshop and scale to fit a 32x32 Used as color fly on unselected tab icons. px artboard with a transparent background. 3. Add the effects seen in Figure 11 for the selected state filter. 4. Export the icon at 32x32 as a PNG file with transparency enabled.

Tools Overview

The Android SDK includes a variety of custom tools that help you develop mobile applications on the Android platform. The most important of these are the Android Emulator and the Android Development Tools plugin for Eclipse, but the SDK also includes a variety of other tools for debugging, packaging, and installing your applications on the emulator. Android Development Tools Plugin (for the Eclipse IDE) The ADT plugin adds powerful extensions to the Eclipse integrated environment, making...

Install the ADT Plugin for Eclipse

It in your respective Eclipse environment. it in your respective Eclipse environment. I.Start Eclipse, then select Help > Software Updates In the 1. Start Eclipse, then select Help > Install New Softare. dialog that appears, click the Available Software tab. 2. In the Available Software dialog, click Add 3. In the Add Site dialog that appears, enter a name for the remote site (e.g., 3. In the Add Site dialog that appears, enter this URL in the Android Plugin) in the Name field. In the...

Preparing for the Exercises

The tutorial assumes that you have some familiarity with basic Android application concepts and terminology. If you are not, you should read Application Fundamentals before continuing. This tutorial also builds on the introductory information provided in the Hello World tutorial, which explains how to set up your Eclipse environment for building Android applications. We recommend you complete the Hello World tutorial before starting this one. 1. Download the project exercises archive (.zip). 2....

Android create avd target 2 name my avd

The tool now asks if you would like to create a custom hardware profile. For the time being, press Return to skip it (no is the default response). That's it. This configures an AVD named my_avd that uses the Android 1.5 platform. The AVD is now ready for use in the emulator. In the above command, the target option is required and specifies the deployment target to run on the emulator. The name option is also required and defines the name for the new AVD.

Calling an IPC Method

Here are the steps a calling class should make to call your remote interface 1. Declare a variable of the interface type that your .aidl file defined. 2. Implement ServiceConnection. 3. Call Context.bindServiceQ, passing in your ServiceConnection implementation. 4. In your implementation of ServiceConnection.onServiceConnectedQ, you will receive an IBinder instance called service . CallYourInterfaceName .Stub.asInterface IBinder service to cast the returned parameter to YourInterface type. 5....

Enabling logcat Logging

The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcat command. You can use the logcat command to view and follow the contents of the system's log buffers. The general usage is adb logcat lt option gt lt filter-spec gt The sections below explain filter specifications and the command options. See...

Create an Unlocalized Application

The first version of the Hello, L10N application will use only the default resource directories res drawable, res layout, andres values . These resources are not localized they are the graphics, layout, and strings that we expect the application to use most often. When a user runs the application in the default locale, or in a locale that the application does not specifically support, the application will load resources from these default directories. The application consists of a simple user...

Implementing IPC Using AIDL

Follow these steps to implement an IPC service using AIDL. 1. Create your .aidl file - This file defines an interface YourInterface.aidl that defines the methods and fields available to a client. 2. Add the .aidl file to your makefile - the ADT Plugin for Eclipse manages this for you . Android includes the compiler, called AIDL, in the tools directory. 3. Implement your interface methods - The AIDL compiler creates an interface in the Java programming language from your AIDL interface. This...

Httpmarketandroidcomsearchqpname or marketsearchqpname

Your application can then compare its own version number against that retrieved. If the retrieved value is greater, your application can show a dialog informing the user that a new version is available. The dialog can offer buttons to begin the download or cancel. 3. If the user clicks the button to begin the download, your application can call startActivity using the ACTION_VIEW Intent, passing the URI received from your web service. The Intent launches the Market application on the device...

Using the App WidgetProvider Class

You must declare your AppWidgetProvider class implementation as a broadcast receiver using the lt receiver gt element in the AndroidManifest see Declaring an App Widget in the Manifest above . The AppWidgetProvider class extends BroadcastReceiver as a convenience class to handle the App Widget broadcasts. The AppWidgetProvider receives only the event broadcasts that are relevant to the App Widget, such as when the App Widget is updated, deleted, enabled, and disabled. When these broadcast...

Resources and Assets

Resources are an integral part of an Android application. In general, these are external elements that you want to include and reference within your application, like images, audio, video, text strings, layouts, themes, etc. Every Android application contains a directory for resources res and a directory for assets assets . Assets are used less often, because their applications are far fewer. You only need to save data as an asset when you need to read the raw bytes. The directories for...

Processes and lifecycles

Android Foreground Process

The Android system tries to maintain an application process for as long as possible, but eventually it will need to remove old processes when memory runs low. To determine which processes to keep and which to kill, Android places each process into an importance hierarchy based on the components running in it and the state of those components. Processes with the lowest importance are eliminated first, then those with the next lowest, and so on. There are five levels in the hierarchy. The...

Nine PatchDrawable

Android Stretchable Background

A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accomodate the contents of the View in which you have placed it as the background. An example use of a NinePatch is the backgrounds used by standard Android buttons buttons must stretch to accommodate strings of various lengths. A NinePatch drawable is a standard PNG image that includes an extra 1-pixel-wide border. It must be saved with the extension .9.png, and saved into the res drawable...

Called when the activity is first created

Notice that the class is based on the Activity class. An Activity is a single application entity that is used to perform actions. An application may have many separate activities, but the user interacts with them one at a time. The onCreate method will be called by the Android system when your Activity starts it is where you should perform all initialization and UI setup. An activity is not required to have a user interface, but usually will. Notice that the class is based on the Activity...

U4 time delta since start in usec

The application is expected to parse all of the header fields, then seek to offset to data from the start of the file. From there it just reads 9-byte records until EOF is reached. u8 start date time in usec is the output from gettimeofday . It's mainly there so that you can tell if the output was generated yesterday or three months ago. method action sits in the two least-significant bits of the method word. The currently defined meanings are 2 - method exited when unrolled by exception...

Tween Animation

Android duration 7 00 gt Screen coordinates not used in this example are 0,0 at the upper left hand corner, and increase as you go down and to the right. Screen coordinates not used in this example are 0,0 at the upper left hand corner, and increase as you go down and to the right. Some values, such as pivotX, can be specified relative to the object itself or relative to the parent. Be sure to use the proper format for what you want 50 for 50 relative to the parent, or 50 for 50 relative to...

Hello Grid View

A GridView displays items in a two-dimensional, scrolling grid. The items are acquired from a ListAdapter. 1. Start a new project Activity called HelloGridView. 2. Find some photos you'd like to use, or copy some from the SDK samples res drawable folder of your project. 3. Open the layout and make it like so lt xml version 1.0 encoding utf-8 gt lt GridView layout width fill parent layout height fill parent 4. Open the HelloGridView Java file. Insert the following for the onCreate method 4. Open...

Creating an App Widget Configuration Activity

If you would like the user to configure settings when he or she adds a new App Widget, you can create an App Widget configuration Activity. This Activity will be automatically launched by the App Widget host and allows the user to configure available settings for the App Widget at create-time, such as the App Widget color, size, update period or other functionality settings. Also, the Activity must be declared in the AppWidgetProviderlnfo XML file, with the android configure attribute see...

Info

This would create a TextView object and set its lines and maxlines properties. Attributes come from three sources Attributes exposed directly by the element. For example, TextView supports TextView_text, as discussed above. Attributes exposed by all the superclasses of that element. For example, the TextView class extends the View class, so the lt TextView gt element supports all the attributes that the lt View gt element exposes a long list, including View_paddingBottom and View_scrollbars....

Audio and Video Playback

Media can be played from anywhere from a raw resource, from a file from the system, or from an available network URL . You can play back the audio data only to the standard output device currently, that is the mobile device speaker or Bluetooth headset. You cannot play sound files in the conversation audio. Perhaps the most common thing to want to do is play back media notably sound within your own applications. Doing this is easy 1. Put the sound or other media resource file into the res raw...

Resolved Issues Changes

The android.jar in this SDK release now includes several classes that were missing from the previous SDK. The android.R.styleable class and its fields were removed from the public API, to better ensure forward-compatibility for applications. The constants declared in android.R.styleable were platform-specific and subject to arbitrary change across versions, so were not suitable for use by applications. You can still access the platform's styleable attributes from your resources or code. To do...

Step

The provided note_edit.xml layout file is the most sophisticated one in the application we will be building, but that doesn't mean it is even close to the kind of sophistication you will be likely to want in real Android applications. Creating a good UI is part art and part science, and the rest is work. Mastery ofDeclaring Layout is an essential part of creating a good looking Android application. Take a look at the Hello Views for some example layouts and how to use them. The ApiDemos sample...

Keytool genkey v keystore myreleasekeykeystore alias alias name keyalg RSA validity 10000

Running the example command above, Keytool prompts you to provide passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore. The keystore and key are protected by the passwords you entered. The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later, to refer to this keystore when signing your application. For more information about Keytool, see...

The alwaysRetain TaskState attribute

If this attribute is set to true in the root activity of a task, the default behavior just described does not happen. The task retains all activities in its stack even after a long period. In contrast, singleTask and singleInstance activities are limited to just one instance. Since these activities are at the root of a task, this limitation means that there is never more than a single instance of the task on the device at one time. Whether the instance can have other activities in its task. A...

Hello Time Picker

A TimePicker is a widget that allows the user to select the time by hour, minute and AM or PM. 1. Start a new project Activity called HelloTimePicker. 2. Open the layout file and make it like so lt xml version 1.0 encoding utf-8 gt lt LinearLayout android layout height wrap content lt TextView android id id timeDisplay android layout width wrap content android layout height wrap content android text gt lt Button android layout width wrap content android layout height wrap content android text...

Upgrade the UI to an XML Layout

The Hello, World example you just completed uses what is called a programmatic UI layout. This means that you constructed and built your application's UI directly in source code. If you've done much UI programming, you're probably familiar with how brittle that approach can sometimes be small changes in layout can result in big source-code headaches. It's also very easy to forget to properly connect Views together, which can result in errors in your layout and wasted time debugging your code....

The allowTask Reparenting attribute

If an activity has its allowTaskReparenting attribute set to true, it can move from the task it starts in to the task it has an affinity for when that task comes to the fore. For example, suppose that an activity that reports weather conditions in selected cities is defined as part of a travel application. It has the same affinity as other activities in the same application the default affinity and it allows reparenting. One of your activities starts the weather reporter, so it initially...

Color palette

Used for outer glow and bevel highlight. 1 r 163 g 163 b 163 2 r 120 g 120 b 120 Used as color fill. Used for inner shadow and bevel shadow. Used for outer glow and bevel highlight. 1 r 163 g 163 b 163 2 r 120 g 120 b 120 Used as color fill. Used for inner shadow and bevel shadow. 1. Create the basic shapes using a tool like Adobe Illustrator. 2. Import the shape into a tool like Adobe Photoshop and scale to fit an image of 48x48 px on a transparent background. Mind the safeframe. 3. Add the...

Binding to Data with Adapter View

The AdapterView is a ViewGroup subclass whose child Views are determined by an Adapter that binds to data of some type. AdapterView is useful whenever you need to display stored data as opposed to resource strings or drawables in your layout. Gallery, ListView, and Spinner are examples of AdapterView subclasses that you can use to bind to a specific type of data and display it in a certain way. AdapterView objects have two main responsibilities 00 Filling the layout with data Handling user...

The finishOnTask Launch attribute

This attribute is like clearTaskOnLaunch, but it operates on a single activity, not an entire task. And it can cause any activity to go away, including the root activity. When it's set to true, the activity remains part of the task only for the current session. If the user leaves and then returns to the task, it no longer is present. There's another way to force activities to be removed from the stack. If an Intent object includes the FLAG ACTIVITY CLEAR TOP flag, and the target task already...

Content Resolver cr getContent Resolver

You can then use the ContentResolver's methods to interact with whatever content providers you're interested in. When a query is initiated, the Android system identifies the content provider that's the target of the query and makes sure that it is up and running. The system instantiates all ContentProvider objects you never need to do it on your own. In fact, you never deal directly with ContentProvider objects at all. Typically, there's just a single instance of each type of ContentProvider....

Essential Tools

When developing in IDEs or editors other than Eclipse, you'll require familiarity with the following Android SDK tools android To create update Android projects and to create move delete AVDs. Android Emulator To run your Android applications on an emulated Android platform. Android Debug Bridge To interface with your emulator or connected device install apps, shell the device, issue commands, etc. . In addition to the above tools, included with the SDK, you'll use the following open source and...

Frame Animation

This is a traditional animation in the sense that it is created with a sequence of different images, played in order, like a roll of film. The AnimationDrawable class is the basis for frame animations. While you can define the frames of an animation in your code, using the AnimationDrawable class API, it's more simply accomplished with a single XML file that lists the frames that compose the animation. Like the tween animation above, the XML file for this kind of animation belongs in the res...

Adding checkboxes and radio buttons

To create a list of multiple-choice items checkboxes or single-choice items radio buttons inside the dialog, use the setMultiChoiceItemsi and setSingleChoiceItemsO methods, respectively. If you create one of these selectable lists in the onCreateDialog callback method, Android manages the state of the list for you. As long as the Activity is active, the dialog remembers the items that were previously selected, but when the user exits the Activity, the selection is lost. Note To save the...

The Flag Activity New Task flag

As described earlier, a new activity is, by default, launched into the task of the activity that called startActivity . It's pushed onto the same stack as the caller. However, if the Intent object passed to startActivity contains the FLAG_ACTIVITY_NEW_TASK flag, the system looks for a different task to house the new activity. Often, as the name of the flag implies, it's a new task. However, it doesn't have to be. If there's already an existing task with the same affinity as the new activity,...

Securing Your Private

Maintaining the security of your private key is of critical importance, both to you and to the user. If you allow someone to use your key, or if you leave your keystore and passwords in an unsecured location such that a third-party could find and use them, your authoring identity and the trust of the user are compromised. If a third party should manage to take your key without your knowledge or permission, that person could sign and distribute applications that maliciously replace your...

Using Resources in Code

Using resources in code is just a matter of knowing the full resource ID and what type of object your resource has been compiled into. Here is the syntax for referring to a resource android.R.resource type.resource name Where resource type is the R subclass that holds a specific type of resource. resource name is the name attribute for resources defined in XML files, or the file name without the extension for resources defined by other file types. Each type of resource will be added to a...

Hello Date Picker

A DatePicker is a widget that allows the user to select a month, day and year. 1. Start a new project Activity called HelloDatePicker. 2. Open the layout file and make it like so 1. Start a new project Activity called HelloDatePicker. 2. Open the layout file and make it like so android layout width wrap content android layout height wrap content lt TextView layout width wrap content layout height wrap content layout width wrap content layout height wrap content For the layout, we're using a...

The clearTaskOnLaunch attribute

If this attribute is set to true in the root activity of a task, the stack is cleared down to the root activity whenever the user leaves the task and returns to it. In other words, it's the polar opposite of alwaysRetainTaskState. The user always returns to the task in its initial state, even after a momentary absence. FLAG_ACTIVITY_CLEAR_TOP is most often used in conjunction with FLAG_ACTIVITY_NEW_TASK. When used together, these flags are a way of locating an existing activity in another task...

Standard widget sizes

There are six standard widget sizes, based on a Home screen grid of 4 x 4 portrait or 4 x 4 landscape cells. These dimensions are the bounding boxes for the six standard widget sizes. The contents of typical widgets don't draw to the edge of these dimensions, but fit inside a frame withing the bounding box, as described in Designing a widget. In portrait orientation, each cell is 80 pixels wide by 100 pixels tall the diagram shows a cell in portrait orientation . The three supported widget...

Hello Form Stuff

This page introduces a variety of widgets, like image buttons, text fields, checkboxes and radio buttons. 1. Start a new project Activity called HelloFormStuff. 2. Your layout file should have a basic LinearLayout lt xml version 1.0 encoding utf-8 gt lt LinearLayout android layout width fill parent gt For each widget you want to add, just put the respective View inside here. Tip As you add new Android code, press Ctrl or Cmd Shift O to import all needed packages.

Selected tab icon

The selected tab icons have the same fill gradient and effects as the menu icon, but with no outer glow. Figure 11. Light, effects, and shadows for selected tab icons. 1. Front part Use fill gradient from color palette. 2. Inner black 20 opacity shadow angle 90 distance 2px 3. Inner bevel depth 1 direction down size 0px highlight white 70 opacity shadow black 25 opacity Figure 11. Light, effects, and shadows for selected tab icons. 1. Front part Use fill gradient from color palette. 2. Inner...

Installing the Win Usb Driver

A WinUsb-based driver is needed in order to use your Android-powered device for development on a Windows machine. The USB installation package can be found in the lt sdk gt usb driver folder of your SDK package. Note If you are connecting an Android-powered device to your computer for the first time, folllow the procedure to Perform a fresh installation. Android SDKs older than version 1.6 included a non-WinUsb-based driver for connecting your device. If you installed the older USB driver and...

Image Button

We'll make it display a message when pressed. 1. Drag the Android image on the right or your own image into the res drawable directory of your project. We'll use this for the 2. Open the layout file and, inside the LinearLayout, add the ImageButton element android id id android button android layout width 100dip android layout height wrap content gt The source of the button is from the res drawable directory, where we've placed the android.png. Tip You can...

Publishing Upgrades on Android Market

The beta version of Android Market does not support notifying your users when you publish a new version of your application. This capability will be added soon, but currently the user must independently initiate download of an upgraded application. When you publish an upgrade, you can assist users by notifying them that the upgrade is available and giving them a way to download the upgraded application from Android Market. Here is a suggested way of tracking installed application versions and...

Void onReceive Context curContext Intent broadcastMsg

When a broadcast message arrives for the receiver, Android calls its onReceive method and passes it the Intent object containing the message. The broadcast receiver is considered to be active only while it is executing this method. When onReceive returns, it is inactive. A process with an active broadcast receiver is protected from being killed. But a process with only inactive components can be killed by the system at any time, when the memory it consumes is needed by other processes. This...

Declaring and Enforcing Permissions

To enforce your own permissions, you must first declare them in your AndroidManifest.xml using one or more For example, an application that wants to control who can start one of its activities could declare a permission for this operation as follows lt manifest package com.me.app.myapp gt For example, an application that needs to monitor incoming SMS messages would specify lt uses-permission SMS gt lt manifest gt android label string permlab deadlyActivity deadlyActivity MONEY gt lt manifest gt...

O For a single record vndandroidcursoritemvnd yourcompanynamecontenttype

For example, a request for train record 122, like this URI, might return this MIME type o For multiple records For example, a request for all train records, like the following URI, If you are exposing byte data that's too big to put in the table itself such as a large bitmap file the field that exposes the data to clients should actually contain a content URI string. This is the field that gives clients access to the data file. The record should also have another field, named _data that lists...

Attributes

A list of one or more URI authorities that identify data under the purview of the content provider. Multiple authorities are listed by separating their names with a semicolon. To avoid conflicts, authority names should use a Java-style naming convention such as com.example.provider.cartoonprovider . Typically, it's the name of the ContentProvider subclass. There is no default. At least one authority must be specified. Whether or not the content provider can be instantiated by the system true if...

Hello Tab Widget

A TabWidget offers the ability to easily draw an interface that uses tabs to navigate between different views. 1. Start a new project Activity called HelloTabWidget. 2. Open the layout file and make it like so lt xml version 1.0 encoding utf-8 gt lt TabHost android layout width fill parent android layout height fill parent gt lt LinearLayout android layout width fill parent android layout height fill parent gt lt TabWidget android layout width fill parent android layout height wrap content gt...

Hello Auto CompleteText View

AutoCompleteTextView is an implementation of the EditText widget that will provide auto-complete suggestions as the user types. The suggestions are extracted from a collection of strings. 1. Start a new project Activity called HelloAutoComplete. 2. Open the layout file. Make it like so lt xml version 1.0 encoding utf-8 gt lt LinearLayout android layout height wrap content gt android text Country gt lt AutoCompleteTextView android id id edit android layout width fill parent android layout height...

Building Custom Components

Android offers a sophisticated and powerful componentized model for building your UI, based on the fundamental layout classes View and ViewGroup. To start with, the platform includes a variety of prebuilt View and ViewGroup subclasses called widgets and layouts, respectively that you can use to construct your UI. A partial list of available widgets includes Button, TextView, EditText, ListView, CheckBox, RadioButton, Gallery, Spinner, and the more specialpurpose AutoCompleteTextView,...

Hello Gallery

A Gallery is a View commonly used to display items in a horizontally scrolling list that locks the current selection at the center. When one is selected, we'll show a message. 1. Start a new project Activity called HelloGallery. 2. Add some images to your res drawable directory. 3. Open the layout file and make it like so lt xml version 1.0 encoding utf-8 gt lt Gallery android id id gallery android layout width fill parent android layout height wrap content 4. Open the HelloGallery.java file....

Hello Web View

A WebView allows you to create your own web browser Activity. In this tutorial, we'll create a simple Activity that can view web pages. 1. Create a new project Activity called HelloWebView. 2. Open the layout file. Insert a WebView so it looks like so lt xml version 1.0 encoding utf-8 gt lt LinearLayout android layout width wrap content android layout height wrap content lt WebView android id id webview android layout width fill parent android layout height fill parent 3. Now open the...

Hello Map View

This tutorial requires that you have the Google Maps external library installed in your SDK environment. By default the Android SDK includes the Google APIs add-on, which in turn includes the Maps external library. If you don't have the Google APIs SDK add-on, you can download it from this location The Google APIs add-on requires Android 1.5 SDK or later release. After installing the add-on in your SDK, set your project properties to use the build target called Google APIs Add-on. See the...

Hello Spinner

A Spinner is a widget that allows the user to select an item from a group. It is similar to a dropdown list and will allow scrolling when the list exceeds the available vertical space on the screen. 1. Start a new project Activity called HelloSpinner. 2. Open the layout file. Make it like so lt xml version 1.0 encoding utf-8 gt lt LinearLayout android layout width fill parent android layout height wrap content gt layout width fill parent layout height wrap content text Please select a planet...

Specifying Your Applications System API Requirements

If your application requires a specific minimum version of the Android platform, or is designed only to support a certain range of Android platform versions, you can specify those version requirements as API Level identifiers in the application's manifest file. Doing so ensures that your application can only be installed on devices that are running a compatible version of the Android system. To specify API Level requirements, add a lt uses-sdk gt element in the application's manifest, with one...

URI Permissions

The standard permission system described so far is often not sufficient when used with content providers. A content provider may want to protect itself with read and write permissions, while its direct clients also need to hand specific URIs to other applications for them to operate on. A typical example is attachments in a mail application. Access to the mail should be protected by permissions, since this is sensitive user data. However, if a URI to an image attachment is given to an image...

Summary of Important View Groups

These objects all hold child UI elements. Some provide their own form of a visible UI, while others are invisible structures that only manage the layout of their child views. Layout that acts as a view frame to display a single object. A horizontal scrolling display of images, from a bound list. Displays a scrolling grid of m columns and n rows. A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of...

Issuing Shell Commands

Adb provides an ash shell that you can use to run a variety of commands on an emulator or device. The command binaries are stored in the file system of the emulator or device, in this location You can use the shell command to issue commands, with or without entering the adb remote shell on the emulator device. To issue a single command without entering a remote shell, use the shell command like this adb -d -e -s lt serialNumber gt shell lt shellCommand gt To drop into a remote shell on a...

For each node dmtracedump shows callname where

lt ref gt -- Call reference number, as used in trace logs lt inc-ms gt -- Inclusive elapsed time milliseconds spent in method, including all child methods lt exc-ms gt -- Exclusive elapsed time milliseconds spent in method, not including any child methods lt numcalls gt -- Number of calls The usage for dmtracedump is The tool then loads trace log data from lt trace-base-name gt .data and lt trace-base-name gt .key. The table below lists the options for dmtracedump. Dump the trace file instead...

Android Emulator

The Android SDK includes a mobile device emulator -- a virtual mobile device that runs on your computer. The emulator lets you prototype, develop, and test Android applications without using a physical device. The Android emulator mimics all of the typical hardware and software features of a typical mobile device, except that it can not receive or place actual phone calls. It provides a variety of navigation and control keys, which you can press using your mouse or keyboard to generate events...

Update Your Eclipse ADT Plugin

If you don't use the Eclipse IDE for development, skip to Run Your Applications. A new version of the ADT Plugin, ADT 0.9.3, is available in conjunction with this SDK release. To use the SDK, you must upgrade your ADT Plugin to version 0.9.3. With ADT 0.9.3, you can still compile your existing applications against multiple platform versions, such as Android 1.5, Android 1.1, and so on. However, ADT 0.9.3 is not compatible with previous versions of the SDK and its tools, so make sure that you...

Unselected tab icon Light effects and shadows

Android Icons With Shadow

Unselected tab icons look just like the selected tab icons, but with a fainter inner shadow, and the same front part gradient as the dialog icons. Figure 10. Light, effects, and shadows for unselected tab icons. 1. Front part gradient overlay angle 90 bottom color r 223 g 223 b 223 top color r 249 g 249 b 249 bottom color location 0 top color location 75 2. Inner black 10 opacity angle 90 distance shadow 2px size 2px 3. Inner bevel depth 1 direction down size 0px angle 90 altitude 10 highlight...

Integer Primary Key Autoincrement

The AUTOINCREMENT descriptor is optional. But without it, SQLite increments an ID counter field to the next number above the largest existing number in the column. If you delete the last row, the next row added will have the same ID as the deleted row. AUTOINCREMENT avoids this by having SQLite increment to the next largest value whether deleted or not. Carefully document the data type of each column. Clients need this information to read the data. If you are handling a new data type, you must...

Filling the Layout with Data

Inserting data into the layout is typically done by binding the AdapterView class to an Adapter, which retireves data from an external source perhaps a list that the code supplies or query results from the device's database . The following code sample does the following 1. Creates a Spinner with an existing View and binds it to a new ArrayAdapter that reads an array of colors from the local resources. 2. Creates another Spinner object from a View and binds it to a new SimpleCursorAdapter that...

The component name is set by setComponent setClass or setClass Name and read by getComponent Action

A string naming the action to be performed or, in the case of broadcast intents, the action that took place and is being reported. The Intent class defines a number of action constants, including these The URI of the data to be acted on and the MIME type of that data. Different actions are paired with different kinds of data specifications. For example, if the action field is ACTION EDIT, the data field would contain the URI of the document to be displayed for editing. If the action is...

Checkable menu items

Any menu item can be used as an interface for turning options on and off. This can be indicated with a checkbox for stand-alone options, or radio buttons for groups of mutually exlusive options see the screenshot, to the right . Note Menu items in the Icon Menu cannot display a checkbox or radio button. If you choose to make items in the Icon Menu checkable, then you must personally indicate the state by swapping the icon and or text each time the state changes between on and off. To make a...

Color value

Value is a color, using web-style syntax, as describe above. Has only one attribute name - The name used in referring to this color. The following code declares two colors, the first fully opaque, and the second translucent. opaque red gt f00 lt color gt translucent red gt 8 0ff0000 lt color gt layout width fill parent layout height wrap content textColor color translucent red

Widget graphics tips and tricks

The Android team has developed a few tricks for aligning widget artwork within standard widget bounding boxes and frames, so the widget aligns visually with other widgets and the other elements of the Home screen, as well as other techniques for creating widgets. Use a screen shot from the Android SDK emulator to align both the shapes and shadows of your widget controls with the Search widget and with other elements on the Home screen. Cut the widget artwork asset based on the full size of a...

PutExtras and getExtras methods

Many instruct the Android system how to launch an activity for example, which task the activity should belong to and how to treat it after it's launched for example, whether it belongs in the list of recent activities . All these flags are defined in the Intent class. The Android system and the applications that come with the platform employ Intent objects both to send out system-originated broadcasts and to activate system-defined components. To see how to structure an...