M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions
+357
View File
@@ -0,0 +1,357 @@
page.title=Android API Levels
@jd:body
<div id="qv-wrapper">
<div id="qv">
<h2>In this document</h2>
<ol>
<li><a href="#intro">What is API Level?</a></li>
<li><a href="#uses">Uses of API Level in Android</a></li>
<li><a href="#considerations">Development Considerations</a>
<ol>
<li><a href="#fc">Application forward compatibility</a></li>
<li><a href="#bc">Application backward compatibility</a></li>
<li><a href="#platform">Selecting a platform version and API Level</a></li>
<li><a href="#apilevel">Declaring a minimum API Level</a></li>
<li><a href="#testing">Testing against higher API Levels</a></li>
</ol>
</li>
<li><a href="#provisional">Using a Provisional API Level</a></li>
<li><a href="#filtering">Filtering the Documentation</a></li>
</ol>
<h2>See also</h2>
<ol>
<li><a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a> manifest element</li>
</ol>
</div>
</div>
<p>As you develop your application on Android, it's useful to understand the
platform's general approach to API change management. It's also important to
understand the API Level identifier and the role it plays in ensuring your
application's compatibility with devices on which it may be installed. </p>
<p>The sections below provide information about API Level and how it affects
your applications. </p>
<p>For information about how to use the "Filter by API Level" control
available in the API reference documentation, see
<a href="#filtering">Filtering the documentation</a> at the
end of this document. </p>
<h2 id="intro">What is API Level?</h2>
<p>API Level is an integer value that uniquely identifies the framework API
revision offered by a version of the Android platform.</p>
<p>The Android platform provides a framework API that applications can use to
interact with the underlying Android system. The framework API consists of:</p>
<ul>
<li>A core set of packages and classes</li>
<li>A set of XML elements and attributes for declaring a manifest file</li>
<li>A set of XML elements and attributes for declaring and accessing resources</li>
<li>A set of Intents</li>
<li>A set of permissions that applications can request, as well as permission
enforcements included in the system</li>
</ul>
<p>Each successive version of the Android platform can include updates to the
Android application framework API that it delivers. </p>
<p>Updates to the framework API are designed so that the new API remains
compatible with earlier versions of the API. That is, most changes in the API
are additive and introduce new or replacement functionality. As parts of the API
are upgraded, the older replaced parts are deprecated but are not removed, so
that existing applications can still use them. In a very small number of cases,
parts of the API may be modified or removed, although typically such changes are
only needed to ensure API robustness and application or system security. All
other API parts from earlier revisions are carried forward without
modification.</p>
<p>The framework API that an Android platform delivers is specified using an
integer identifier called "API Level". Each Android platform version supports
exactly one API Level, although support is implicit for all earlier API Levels
(down to API Level 1). The initial release of the Android platform provided
API Level 1 and subsequent releases have incremented the API Level.</p>
<p>The following table specifies the API Level supported by each version of the
Android platform.</p>
<table>
<tr><th>Platform Version</th><th>API Level</th></tr>
<tr><td>Android 2.3.3</td><td>10</td></tr>
<tr><td>Android 2.3</td><td>9</td></tr>
<tr><td>Android 2.2</td><td>8</td></tr>
<tr><td>Android 2.1</td><td>7</td></tr>
<tr><td>Android 2.0.1</td><td>6</td></tr>
<tr><td>Android 2.0</td><td>5</td></tr>
<tr><td>Android 1.6</td><td>4</td></tr>
<tr><td>Android 1.5</td><td>3</td></tr>
<tr><td>Android 1.1</td><td>2</td></tr>
<tr><td>Android 1.0</td><td>1</td></tr>
</table>
<h2 id="uses">Uses of API Level in Android</h2>
<p>The API Level identifier serves a key role in ensuring the best possible
experience for users and application developers:
<ul>
<li>It lets the Android platform describe the maximum framework API revision
that it supports</li>
<li>It lets applications describe the framework API revision that they
require</li>
<li>It lets the system negotiate the installation of applications on the user's
device, such that version-incompatible applications are not installed.</li>
</ul>
<p>Each Android platform version stores its API Level identifier internally, in
the Android system itself. </p>
<p>Applications can use a manifest element provided by the framework API &mdash;
<code>&lt;uses-sdk&gt;</code> &mdash; to describe the minimum and maximum API
Levels under which they are able to run, as well as the preferred API Level that
they are designed to support. The element offers three key attributes:</p>
<ul>
<li><code>android:minSdkVersion</code> &mdash; Specifies the minimum API Level
on which the application is able to run. The default value is "1".</li>
<li><code>android:targetSdkVersion</code> &mdash; Specifies the API Level
on which the application is designed to run. In some cases, this allows the
application to use manifest elements or behaviors defined in the target
API Level, rather than being restricted to using only those defined
for the minimum API Level.</li>
<li><code>android:maxSdkVersion</code> &mdash; Specifies the maximum API Level
on which the application is able to run. <strong>Important:</strong> Please read the <a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><code>&lt;uses-sdk&gt;</code></a>
documentation before using this attribute. </li>
</ul>
<p>For example, to specify the minimum system API Level that an application
requires in order to run, the application would include in its manifest a
<code>&lt;uses-sdk&gt;</code> element with a <code>android:minSdkVersion</code>
attribute. The value of <code>android:minSdkVersion</code> would be the integer
corresponding to the API Level of the earliest version of the Android platform
under which the application can run. </p>
<p>When the user attempts to install an application, or when revalidating an
appplication after a system update, the Android system first checks the
<code>&lt;uses-sdk&gt;</code> attributes in the application's manifest and
compares the values against its own internal API Level. The system allows the
installation to begin only if these conditions are met:</p>
<ul>
<li>If a <code>android:minSdkVersion</code> attribute is declared, its value
must be less than or equal to the system's API Level integer. If not declared,
the system assumes that the application requires API Level 1. </li>
<li>If a <code>android:maxSdkVersion</code> attribute is declared, its value
must be equal to or greater than the system's API Level integer.
If not declared, the system assumes that the application
has no maximum API Level. Please read the <a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><code>&lt;uses-sdk&gt;</code></a>
documentation for more information about how the system handles this attribute.</li>
</ul>
<p>When declared in an application's manifest, a <code>&lt;uses-sdk&gt;</code>
element might look like this: </p>
<pre>&lt;manifest&gt;
&lt;uses-sdk android:minSdkVersion="5" /&gt;
...
&lt;/manifest&gt;</pre>
<p>The principal reason that an application would declare an API Level in
<code>android:minSdkVersion</code> is to tell the Android system that it is
using APIs that were <em>introduced</em> in the API Level specified. If the
application were to be somehow installed on a platform with a lower API Level,
then it would crash at run-time when it tried to access APIs that don't exist.
The system prevents such an outcome by not allowing the application to be
installed if the lowest API Level it requires is higher than that of the
platform version on the target device.</p>
<p>For example, the {@link android.appwidget} package was introduced with API
Level 3. If an application uses that API, it must declare a
<code>android:minSdkVersion</code> attribute with a value of "3". The
application will then be installable on platforms such as Android 1.5 (API Level
3) and Android 1.6 (API Level 4), but not on the Android 1.1 (API Level 2) and
Android 1.0 platforms (API Level 1).</p>
<p>For more information about how to specify an application's API Level
requirements, see the <a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><code>&lt;uses-sdk&gt;</code></a>
section of the manifest file documentation.</p>
<h2 id="considerations">Development Considerations</h2>
<p>The sections below provide information related to API level that you should
consider when developing your application.</p>
<h3 id="fc">Application forward compatibility</h3>
<p>Android applications are generally forward-compatible with new versions of
the Android platform.</p>
<p>Because almost all changes to the framework API are additive, an Android
application developed using any given version of the API (as specified by its
API Level) is forward-compatible with later versions of the Android platform and
higher API levels. The application should be able to run on all later versions
of the Android platform, except in isolated cases where the application uses a
part of the API that is later removed for some reason. </p>
<p>Forward compatibility is important because many Android-powered devices
receive over-the-air (OTA) system updates. The user may install your
application and use it successfully, then later receive an OTA update to a new
version of the Android platform. Once the update is installed, your application
will run in a new run-time version of the environment, but one that has the API
and system capabilities that your application depends on. </p>
<p>In some cases, changes <em>below</em> the API, such those in the underlying
system itself, may affect your application when it is run in the new
environment. For that reason it's important for you, as the application
developer, to understand how the application will look and behave in each system
environment. To help you test your application on various versions of the Android
platform, the Android SDK includes multiple platforms that you can download.
Each platform includes a compatible system image that you can run in an AVD, to
test your application. </p>
<h3 id="bc">Application backward compatibility</h3>
<p>Android applications are not necessarily backward compatible with versions of
the Android platform older than the version against which they were compiled.
</p>
<p>Each new version of the Android platform can include new framework APIs, such
as those that give applications access to new platform capabilities or replace
existing API parts. The new APIs are accessible to applications when running on
the new platform and, as mentioned above, also when running on later versions of
the platform, as specified by API Level. Conversely, because earlier versions of
the platform do not include the new APIs, applications that use the new APIs are
unable to run on those platforms.</p>
<p>Although it's unlikely that an Android-powered device would be downgraded to
a previous version of the platform, it's important to realize that there are
likely to be many devices in the field that run earlier versions of the
platform. Even among devices that receive OTA updates, some might lag and
might not receive an update for a significant amount of time. </p>
<h3 id="platform">Selecting a platform version and API Level</h3>
<p>When you are developing your application, you will need to choose
the platform version against which you will compile the application. In
general, you should compile your application against the lowest possible
version of the platform that your application can support.
<p>You can determine the lowest possible platform version by compiling the
application against successively lower build targets. After you determine the
lowest version, you should create an AVD using the corresponding platform
version (and API Level) and fully test your application. Make sure to declare a
<code>android:minSdkVersion</code> attribute in the application's manifest and
set its value to the API Level of the platform version. </p>
<h3 id="apilevel">Declaring a minimum API Level</h3>
<p>If you build an application that uses APIs or system features introduced in
the latest platform version, you should set the
<code>android:minSdkVersion</code> attribute to the API Level of the latest
platform version. This ensures that users will only be able to install your
application if their devices are running a compatible version of the Android
platform. In turn, this ensures that your application can function properly on
their devices. </p>
<p>If your application uses APIs introduced in the latest platform version but
does <em>not</em> declare a <code>android:minSdkVersion</code> attribute, then
it will run properly on devices running the latest version of the platform, but
<em>not</em> on devices running earlier versions of the platform. In the latter
case, the application will crash at runtime when it tries to use APIs that don't
exist on the earlier versions.</p>
<h3 id="testing">Testing against higher API Levels</h3>
<p>After compiling your application, you should make sure to test it on the
platform specified in the application's <code>android:minSdkVersion</code>
attribute. To do so, create an AVD that uses the platform version required by
your application. Additionally, to ensure forward-compatibility, you should run
and test the application on all platforms that use a higher API Level than that
used by your application. </p>
<p>The Android SDK includes multiple platform versions that you can use,
including the latest version, and provides an updater tool that you can use to
download other platform versions as necessary. </p>
<p>To access the updater, use the <code>android</code> command-line tool,
located in the &lt;sdk&gt;/tools directory. You can launch the Updater by using
the <code>android</code> command without specifying any options. You can
also simply double-click the android.bat (Windows) or android (OS X/Linux) file.
In ADT, you can also access the updater by selecting
<strong>Window</strong>&nbsp;>&nbsp;<strong>Android SDK and AVD
Manager</strong>.</p>
<p>To run your application against different platform versions in the emulator,
create an AVD for each platform version that you want to test. For more
information about AVDs, see <a
href="{@docRoot}guide/developing/tools/avd.html">Android Virtual Devices</a>. If
you are using a physical device for testing, ensure that you know the API Level
of the Android platform it runs. See the table at the top of this document for
a list of platform versions and their API Levels. </p>
<h2 id="provisional">Using a Provisional API Level</h2>
<p>In some cases, an "Early Look" Android SDK platform may be available. To let
you begin developing on the platform although the APIs may not be final, the
platform's API Level integer will not be specified. You must instead use the
platform's <em>provisional API Level</em> in your application manifest, in order
to build applications against the platform. A provisional API Level is not an
integer, but a string matching the codename of the unreleased platform version.
The provisional API Level will be specified in the release notes for the Early
Look SDK release notes and is case-sensitive.</p>
<p>The use of a provisional API Level is designed to protect developers and
device users from inadvertently publishing or installing applications based on
the Early Look framework API, which may not run properly on actual devices
running the final system image.</p>
<p>The provisional API Level will only be valid while using the Early Look SDK
and can only be used to run applications in the emulator. An application using
the provisional API Level can never be installed on an Android device. At the
final release of the platform, you must replace any instances of the provisional
API Level in your application manifest with the final platform's actual API
Level integer.</p>
<h2 id="filtering">Filtering the Reference Documentation by API Level</h2>
<p>Reference documentation pages on the Android Developers site offer a "Filter
by API Level" control in the top-right area of each page. You can use the
control to show documentation only for parts of the API that are actually
accessible to your application, based on the API Level that it specifies in
the <code>android:minSdkVersion</code> attribute of its manifest file. </p>
<p>To use filtering, select the checkbox to enable filtering, just below the
page search box. Then set the "Filter by API Level" control to the same API
Level as specified by your application. Notice that APIs introduced in a later
API Level are then grayed out and their content is masked, since they would not
be accessible to your application. </p>
<p>Filtering by API Level in the documentation does not provide a view
of what is new or introduced in each API Level &mdash; it simply provides a way
to view the entire API associated with a given API Level, while excluding API
elements introduced in later API Levels.</p>
<p>If you decide that you don't want to filter the API documentation, just
disable the feature using the checkbox. By default, API Level filtering is
disabled, so that you can view the full framework API, regardless of API Level.
</p>
<p>Also note that the reference documentation for individual API elements
specifies the API Level at which each element was introduced. The API Level
for packages and classes is specified as "Since &lt;api level&gt;" at the
top-right corner of the content area on each documentation page. The API Level
for class members is specified in their detailed description headers,
at the right margin. </p>
@@ -0,0 +1,106 @@
page.title=Reference of Available Intents
@jd:body
<p>This document describes the default applications and settings that Google provides
in their standard Android implementation. </p>
<h3>Intents handled by Google Android applications<a name="googleintents" id="googleintents"></a></h3>
<p> Android ships with Activities that handle the following Intent URI/Action pairs. </p>
<table width="100%" border="1">
<tr>
<th scope="col">Scheme</th>
<th scope="col">Action<br />
android.intent.action.<em>value</em></th>
<th scope="col">Description</th>
</tr>
<tr>
<td>http://<em>web_address</em><br />
https://<em>web_address</em></td>
<td>VIEW</td>
<td>Open a browser window to the URL specified. </td>
</tr>
<tr>
<td>&quot;&quot; (empty string) <br />
http://<em>web_address</em><br />
https://<em>web_address</em></td>
<td>WEB_SEARCH</td>
<td>Opens the file at the location on the device in the browser. </td>
</tr>
<tr>
<td height="103">tel: <em>phone_number</em></td>
<td>CALL</td>
<td><p>Calls the entered phone number. Valid telephone numbers as defined
in <a href="http://tools.ietf.org/html/rfc3966">the IETF RFC 3966</a> are
accepted. Valid examples include the following:</p>
<ul>
<li>tel:2125551212 </li>
<li>tel:
(212) 555 1212</li>
</ul>
<p>The dialer is good at normalizing some kinds of schemes: for example
telephone numbers, so the schema described isn't strictly required
in the {@link android.net.Uri#parse(java.lang.String)
Uri(URI string)} factory. However, if you have not tried a
schema or are unsure whether it can be handled, use the {@link
android.net.Uri#fromParts(java.lang.String, java.lang.String,
java.lang.String) Uri.fromParts(scheme, ssp, fragment)} factory
instead.</p>
<p><strong><em>Note:</em></strong>&nbsp;&nbsp;&nbsp;This requires your
application to request the following permission in your manifest: <code>&lt;uses-permission
id=&quot;android.permission.CALL_PHONE&quot; /&gt;</code></p></td>
</tr>
<tr>
<td><p>tel:<em>phone_number</em><br />
voicemail:</p> </td>
<td>DIAL</td>
<td><p>Dials (but does not actually initiate the call) the number given
(or the stored voicemail on the phone). Telephone number normalization
described for CALL applies to DIAL as well. </p> </td>
</tr>
<tr>
<td>geo:<em>latitude</em>,<em>longitude</em><br />
geo:<em>latitude</em>,<em>longitude</em>?z=<em>zoom</em><br />
geo:0,0?q=<em>my+street+address</em><br />
geo:0,0?q=<em>business+near+city</em><br />
</td>
<td>VIEW</td>
<td>Opens the Maps application to the given location or query. The Geo URI scheme
(not fully supported) is <a href="http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00">currently under
development</a>.<p>
The <em>z</em> field specifies the zoom level. A zoom level of 1 shows the whole Earth, centered at the
given <em>lat</em>,<em>lng</em>. A zoom level of 2 shows a quarter of the Earth, and so on. The highest
zoom level is 23. A larger zoom level will be clamped to 23.
</td>
</tr>
<tr>
<td>google.streetview:cbll=<em>lat</em>,<em>lng</em>&amp;cbp=1,<em>yaw</em>,,<em>pitch</em>,<em>zoom</em>&amp;mz=<em>mapZoom</em>
</td>
<td>VIEW</td>
<td>Opens the Street View application to the given location. The URI scheme is
based on the syntax used for Street View panorama information in Google Maps URLs.<p>
The cbll field is required. The cbp and mz fields are optional.<p>
<table border="1">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>lat</td><td>latitude</td></tr>
<tr><td>lng</td><td>longitude</td></tr>
<tr><td>yaw</td><td>Panorama center-of-view in degrees clockwise from North.<br />
<b>Note:</b> The two commas after the yaw parameter are required. They are present
for backwards-compatibility reasons.</td></tr>
<tr><td>pitch</td><td>Panorama center-of-view in degrees from
-90 (look straight up) to 90 (look straight down.)</td></tr>
<tr><td>zoom</td><td>Panorama zoom. 1.0 = normal zoom, 2.0 = zoomed in 2x, 3.0 = zoomed in 4x, and so on.<br />
A zoom of 1.0 is 90 degree horizontal FOV for a nominal
landscape mode 4 x 3 aspect ratio display.
Android phones in portrait mode will adjust the zoom so that
the vertical FOV is approximately the same as the landscape vertical
FOV. This means that the horizontal FOV of an Android phone in portrait
mode is much narrower than in landscape mode. This is done to minimize
the fisheye lens effect that would be present if a 90 degree horizontal
FOV was used in portrait mode.</td></tr>
<tr><td>mapZoom</td><td>The map zoom of the map location associated with this panorama. This value is passed on to the
Maps activity when the Street View "Go to Maps" menu item is chosen. It corresponds to the <em>z</em> parameter in
the geo: intent.</td></tr>
</table>
</td>
</tr>
</table>
<p></p>
@@ -0,0 +1,819 @@
page.title=Common Tasks and How to Do Them in Android
parent.title=FAQs, Tips, and How-to
parent.link=index.html
@jd:body
<ul>
<li><a href="#neweclipseandroidproject">Creating an Android Application using
the Eclipse plugin</a></li>
<li><a href="#newandroidprojectnoeclipse">Creating an Android Application without
the Eclipse plugin</a></li>
<li><a href="#addexternallibrary">Adding an External Library (.jar) using Eclipse</a></li>
<li><a href="#implementcallbacks">Implementing Activity callbacks</a> (Android
calls your activity at various key moments in its life cycle. You must know
how to handle each of these to draw your screen, initialize class members,
and acquire data.)</li>
<li><a href="#opennewscreen">Opening a new screen</a></li>
<li><a href="#listening">Listening for button clicks </a></li>
<li><a href="#configurewindowproperties">Configuring general window properties </a></li>
<li><a href="#localhostalias">Referring to localhost from the emulated environment</a></li>
<li><a href="#appstate">Storing and retrieving state</a></li>
<li><a href="{@docRoot}guide/topics/data/data-storage.html#preferences">Storing and retrieving preferences</a></li>
<li><a href="#storingandretrieving">Storing and retrieving larger or more complex
persistent data</a> (files and data) </li>
<li><a href="#playback">Playing audio, video, still, or other media files</a></li>
<li><a href="#broadcastreceivers">Listening for and broadcasting global messages
and setting alarms</a></li>
<li><a href="#alerts">Displaying alerts </a></li>
<li><a href="#progressbar">Displaying a progress bar</a> </li>
<li><a href="#addmenuitems">Adding items to the screen menu</a> </li>
<li><a href="#webpage">Display a web page</a> </li>
<li><a href="#binding">Binding to data</a></li>
<li><a href="#handle">Getting a Handle to a Screen Element</a></li>
<li><a href="#captureimages">Capture images from the phone camera </a></li>
<li><a href="#threading">Handling expensive operations in the UI thread</a></li>
<li><a href="#selectingtext">Selecting, highlighting, or styling portions of
text</a></li>
<li><a href="#querymap">Utilizing attributes in a Map query</a></li>
<li><a href="#filelist">List of files for an Android application</a></li>
<li><a href="#logging">Print messages to a log file</a></li>
</ul>
<p>The ApiDemos sample application includes many, many examples of common
tasks and UI features. See the code inside
<code>&lt;sdk&gt;samples/ApiDemos</code> and the other sample applications
under the <code>samples/</code> folder in the SDK.</p>
<h2 id="neweclipseandroidproject">Creating an Android Application using the Eclipse Plugin</h2>
<p>Using the Android Eclipse plugin is the fastest and easiest way
to start creating a new Android application. The plugin automatically generates
the correct project structure for your application, and keeps the resources
compiled for you automatically.</p>
<p>It is still a good idea to know what is going on though. Take a look at <a
href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a>
to understand the basics of how an Android application works.</p>
<p>You should also take a look at the ApiDemos application and the other sample
applications included in the SDK, in the <code>&lt;sdk&gt;/samples/</code>
folder in the SDK.</p>
<p>Finally, a great way to started with Android development in Eclipse is to
follow both the <a href="{@docRoot}resources/tutorials/hello-world.html">Hello,
World</a> and <a
href="{@docRoot}resources/tutorials/notepad/index.html">Notepad</a> code
tutorials. In particular, the start of the Hello Android tutorial is an
excellent introduction to creating a new Android application in Eclipse.</p>
<h2 id="newandroidprojectnoeclipse">Creating an Android Application without the Eclipse Plugin</h2>
<p>This topic describes the manual steps in creating an Android application.
Before reading this, you should read <a
href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a>
to understand the basics of how an Android application works. You might also
want to look at the sample code included with the Android SDK, in the
<code>&lt;sdk&gt;/samples/</code> directory. </p>
<p>Here is a list of the basic steps in building an application.</p>
<ol>
<li><strong>Create your required resource files</strong> &nbsp;&nbsp;This includes
the AndroidManifest.xml global description file, string files that your application
needs, and layout files describing your user interface. A full list of optional
and required files and syntax details for each is given in <a href="#filelist">File
List for an Android Application</a>. </li>
<li><strong>Design your user interface</strong> &nbsp;&nbsp;See <a
href="{@docRoot}guide/topics/ui/index.html">User Interface</a> for
details on elements of the Android screen. </li>
<li><strong>Implement your Activity </strong>(this page)<strong>&nbsp;&nbsp; </strong> You
will create one class/file for each screen in your application. Screens will
inherit from an {@link android.app android.app} class, typically {@link android.app.Activity
android.app.Activity} for basic screens, {@link android.app.ListActivity
android.app.ListActivity} for list screens, or {@link android.app.Dialog
android.app.Dialog} for dialog boxes. You will implement the required callbacks
that let you draw your screen, query data, and commit changes, and also perform
any required tasks such as opening additional screens or reading data from
the device. Common tasks, such as opening a new screen or reading data from
the device, are described below.
The list of files you'll need for your application are described in <a href="#filelist">List
of Files for an Android Application</a>. </li>
<li><strong><a href="{@docRoot}guide/developing/other-ide.html#buildingwithant">Build and install your
package</a>.</strong> The Android SDK has some nice tools for generating
projects and debugging code. </li>
</ol>
<h2 id="addexternallibrary">Adding an External Library (.jar) using Eclipse</h2>
<p>
You can use a third party JAR in your application by adding it to your Eclipse project as follows:
</p>
<ol>
<li>
In the <strong>Package Explorer</strong> panel, right-click on your project and select <strong>Properties</strong>.
<li>
Select <strong>Java Build Path</strong>, then the tab <strong>Libraries</strong>.
<li>
Press the <strong>Add External JARs...</strong> button and select the JAR file.
</ol>
<p>
Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select <strong>Add Library...</strong> instead.</p>
<p>
It is not necessary to put external JARs in the assets folder.
</p>
<a name="implementcallbacks" id="implementcallbacks"></a>
<h2>Implementing Activity Callbacks</h2>
<p>Android calls a number of callbacks to let you draw your screen, store data before
pausing, and refresh data after closing. You must implement at least some of
these methods. See <a href="{@docRoot}guide/topics/fundamentals.html#lcycles">Lifecycles</a>
discussion in Application Fundamentals to learn when and in what order these methods
are called. Here are some of the standard types of screen classes that Android provides:</p>
<ul>
<li>{@link android.app.Activity android.app.Activity} - This is a standard screen,
with no specialization.</li>
<li>{@link android.app.ListActivity android.app.ListActivity} - This is a screen
that is used to display a list of something. It hosts a ListView object,
and exposes methods to let you identify the selected item, receive callbacks
when the selected item changes, and perform other list-related actions. </li>
<li>{@link android.app.Dialog android.app.Dialog} - This is a small, popup dialog-style
window that isn't intended to remain in the history stack. (It is not resizeable
or moveable by the user.)</li>
</ul>
<a name="opennewscreen" id="opennewscreen"></a><h2>Opening a New Screen</h2>
<p>Your Activity will often need to open another Activity screen as it progresses.
This new screen can be part of the same application or part of another application,
the new screen can be floating or full screen, it can return a result, and you
can decide whether to close this screen and remove it from the history stack
when you are done with it, or to keep the screen open in history. These next
sections describe all these options. </p>
<h3>Floating or full?<a name="floatingorfull" id="floatingorfull"></a></h3>
<p>When you open a new screen you can decide whether to make it transparent or floating,
or full-screen. The choice of new screen affects the event sequence of events
in the old screen (if the new screen obscures the old screen, a different
series of events is called in the old screen). See <a
href="{@docRoot}guide/topics/fundamentals.html#lcycles">Lifecycles</a> discussion
in Application Fundamentals for details. </p>
<p>Transparent or floating windows are implemented in three
standard ways: </p>
<ul>
<li>Create an {@link android.app.Dialog app.Dialog} class </li>
<li>Create an {@link android.app.AlertDialog app.AlertDialog} class </li>
<li>Set the {@link android.R.style#Theme_Dialog} <em>theme</em> attribute to <code>&#064;android:style/Theme.Dialog</code>
in your AndroidManifest.xml file. For example:
<pre>&lt;activity class=&quot;AddRssItem&quot; android:label=&quot;Add an item&quot; android:theme=&quot;&#064;android:style/Theme.Dialog&quot;/&gt;
</pre></li>
</ul>
<p>Calling startActivity() or startActivityForResult() will open a new screen in whatever
way it defines itself (if it uses a floating theme it will be floating,
otherwise it will be full screen). </p>
<h3>Opening a Screen </h3>
<p>When you want to open a new screen, you can either explicitly specify the activity
class to open, or you can let the operating system decide which screen to open,
based upon the data and various parameters you pass in. A screen is opened by
calling {@link android.app.Activity#startActivity(android.content.Intent) startActivity}
and passing in an {@link android.content.Intent Intent} object, which specifies
the criteria for the handling screen. To specify a specific screen, call Intent.setClass
or setClassName with the exact activity class to open. Otherwise, set a variety
of values and data, and let Android decide which screen is appropriate to open.
Android will find one or zero Activities that match the specified requirements;
it will never open multiple activities for a single request. More information
on Intents and how Android resolves them to a specific class is given in the
{@link android.content.Intent Intent} topic. </p>
<a name="intentexamples" id="intentexamples"></a><h3>Some Intent examples </h3>
<p>The following snippet loads the com.android.samples.Animation1 class, and
passes it some arbitrary data.:</p>
<pre>Intent myIntent = new Intent();
myIntent.setClassName(&quot;com.android.samples&quot;, &quot;com.android.samples.Animation1&quot;);
myIntent.putExtra(&quot;com.android.samples.SpecialValue&quot;, &quot;Hello, Joe!&quot;); // key/value pair, where key needs current package prefix.
startActivity(myIntent); </pre>
<p>The next snippet requests that a Web page be opened by specifying the VIEW action,
and a URI data string starting with &quot;http://&quot; schema:</p>
<pre>Intent myIntent = new Intent(Intent.VIEW_ACTION, Uri.parse(&quot;http://www.google.com&quot;));</pre>
<p>Here is the intent filter from the AndroidManifest.xml file for com.android.browser:</p>
<pre>&lt;intent-filter&gt;
&lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;
&lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
&lt;scheme android:name=&quot;http&quot; /&gt;
&lt;scheme android:name=&quot;https&quot; /&gt;
&lt;scheme android:name=&quot;file&quot; /&gt;
&lt;/intent-filter&gt; </pre>
<p>Android defines a number of standard values, for instance the action constants
defined by {@link android.content.Intent}. You can define custom values, but
both the caller and handler must use them. See the &lt;intent-filter&gt;
tag description in <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml
File</a> for more information on the manifest syntax for the handling
application. </p>
<a name="returningaresult" id="returningaresult"></a><h3>Returning a Result from a Screen</h3>
<p>A window can return a result after it closes. This result will be passed back
into the calling Activity's {@link android.app.Activity#onActivityResult(int,int,android.content.Intent)
onActivityResult()} method, which can supply an Intent containing arbitrary data, along with
the request code passed to startActivityForResult(). Note that you must call the {@link
android.app.Activity#startActivityForResult(android.content.Intent,int) startActivityForResult()}
method that accepts a request code parameter to get this callback. The following
code demonstrates opening a new screen and retrieving a result. </p>
<pre>// Open the new screen.
public void onClick(View v){
// Start the activity whose result we want to retrieve. The
// result will come back with request code GET_CODE.
Intent intent = new Intent(this, com.example.app.ChooseYourBoxer.class);
startActivityForResult(intent, CHOOSE_FIGHTER);
}
// Listen for results.
protected void onActivityResult(int requestCode, int resultCode, Intent data){
// See which child activity is calling us back.
switch (resultCode) {
case CHOOSE_FIGHTER:
// This is the standard resultCode that is sent back if the
// activity crashed or didn't doesn't supply an explicit result.
if (resultCode == RESULT_CANCELED){
myMessageboxFunction("Fight cancelled");
}
else {
myFightFunction(data);
}
default:
break;
}
}
// Class SentResult
// Temporary screen to let the user choose something.
private OnClickListener mLincolnListener = new OnClickListener(){
public void onClick(View v) {
Bundle stats = new Bundle();
stats.putString("height","6\'4\"");
stats.putString("weight", "190 lbs");
stats.putString("reach", "74\"");
setResult(RESULT_OK, "Lincoln", stats);
finish();
}
};
private OnClickListener mWashingtonListener = new OnClickListener() {
public void onClick(View v){
Bundle stats = new Bundle();
stats.putString("height","6\'2\"");
stats.putString("weight", "190 lbs");
stats.putString("reach", "73\"");
setResult(RESULT_OK, "Washington", Bundle);
finish();
}
};
</pre>
<h3>Lifetime of the new screen </h3>
<p>An activity can remove itself from the history stack by calling {@link android.app.Activity#finish()
Activity.finish()} on itself, or the activity that opened the screen can call
{@link android.app.Activity#finishActivity(int) Activity.finishActivity()}
on any screens that it opens to close them. </p>
<a name="listening" id="listening"></a><h2>Listening for Button Clicks</h2>
<p>Button click and other UI event capturing are covered in <a href="{@docRoot}guide/topics/ui/ui-events.html">Handling UI Events</a> on the UI Design page.</p>
<a name="configurewindowproperties" id="configurewindowproperties"></a><h2>Configuring General Window Properties</h2>
<p>You can set a number of general window properties, such as whether to display
a title, whether the window is floating, and whether it displays an icon, by
calling methods on the {@link android.view.Window Window} member
of the underlying View object for the window. Examples include calling {@link
android.app.Activity#getWindow() getWindow().requestFeature()} (or the convenience
method {@link android.app.Activity#requestWindowFeature(int) requestWindowFeature(<em>some_feature</em>)})
to hide the title. Here is an example of hiding the title bar:</p>
<pre>//Hide the title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
</pre>
<p>A better way to achieve the same end is to specify a theme in your Android
Manifest file:</p>
<pre>&lt;application android:icon="@drawable/icon" android:theme="@android:style/Theme.NoTitleBar"&gt;
</pre>
<p>This is preferable because it tells the system not to show a title bar while
your application is starting up. With the explicit method call, your application
will have a title bar visible to the user until <code>onCreate</code> runs.</p>
<p>(Note that this can be applied to either the <code>&lt;application&gt;</code>
tag or to individual <code>&lt;activity&gt;</code> tags.)</p>
<a name="localhostalias" id="localhostalias"></a><h2>Referring to localhost from the emulated environment</h2>
<p>
If you need to refer to your host computer's <em>localhost</em>, such as when you
want the emulator client to contact a server running on the same host, use the alias
<code>10.0.2.2</code> to refer to the host computer's loopback interface.
From the emulator's perspective, localhost (<code>127.0.0.1</code>) refers to its own
loopback interface.
</p>
<a name="appstate" id="appstate"></a><h2>Storing and Retrieving State</h2>
<p>If your application is dumped from memory because of space concerns, it will lose
all user interface state information such as checkbox state and text box values
as well as class member values. Android calls {@link android.app.Activity#onSaveInstanceState(android.os.Bundle)
Activity.onSaveInstanceState} before it pauses the application. This method hands in a {@link
android.os.Bundle Bundle} that can be used to store name/value pairs that will
persist and be handed back to the application even if it is dropped from memory.
Android will pass this Bundle back to you when it calls {@link android.app.Activity#onCreate(android.os.Bundle)
onCreate()}. This Bundle only exists while the application is still in the history
stack (whether or not it has been removed from memory) and will be lost when
the application is finalized. See the topics for {@link android.app.Activity#onSaveInstanceState} and
{@link android.app.Activity#onCreate} for
examples of storing and retrieving state.</p>
<p>Read more about the lifecycle of an application in <a href="{@docRoot}guide/topics/fundamentals.html">Application Fundamentals</a>.</p>
<h3>Storing and Retrieving Larger or More Complex Persistent Data<a name="storingandretrieving" id="storingandretrieving"></a></h3>
<p>Your application can store files or complex collection objects, and reserve them
for private use by itself or other activities in the application, or it can expose
its data to all other applications on the device. See <a href="{@docRoot}guide/topics/data/data-storage.html">Storing,
Retrieving, and Exposing Data</a> to learn how to store and retrieve private data,
how to store and retrieve common data from the device, and how to expose your
private data to other applications.</p>
<a name="playback" id="playback"></a><h2>Playing Media Files</h2>
<p>Please see the document <a href="{@docRoot}guide/topics/media/index.html">Audio and Video</a> for more details.</p>
<a name="broadcastreceivers" id="broadcastreceivers"></a><h2>Listening For and Broadcasting Global Messages, and Setting Alarms</h2>
<p>You can create a listening class that can be notified or even instantiated whenever
a specific type of system message is sent.
</p>
<p>The listening classes, called broadcast receivers, extend {@link android.content.BroadcastReceiver
BroadcastReceiver}. If you want Android to instantiate the object whenever an appropriate
intent notification is sent, define the receiver with a <code>&lt;receiver&gt;</code> element
in the AndroidManifest.xml file. If the caller is expected to instantiate the
object in preparation to receive a message, this is not required. The receiver
will get a call to their {@link android.content.BroadcastReceiver#onReceive(android.content.Context,android.content.Intent)
BroadcastReceiver.onReceive()} method. A receiver can define an <code>&lt;intent-filter&gt;</code> tag
that describes the types of messages it will receive. Just as Android's IntentResolver
will look for appropriate Activity matches for a startActivity() call, it will
look for any matching Receivers (but it will send the message to all matching
receivers, not to the &quot;best&quot; match). </p>
<p>To send a notification, the caller creates an {@link android.content.Intent Intent}
object and calls {@link android.app.Activity#sendBroadcast(android.content.Intent)
Context.sendBroadcast()} with that Intent. Multiple recipients can receive
the same message. You can broadcast an Intent message to an intent receiver in
any application, not only your own. If the receiving class is not registered
using <code>&lt;receiver&gt;</code> in its manifest, you can dynamically instantiate
and register a receiver by calling {@link android.content.Context#registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter)
Context.registerReceiver()}. </p>
<p>Receivers can include intent filters to specify what kinds of intents they are
listening for. Alternatively, if you expect a single known caller to contact
a single known receiver, the receiver does not specify an intent filter, and
the caller specifies the receiver's class name in the Intent by calling {@link
android.content.Intent#setClassName(java.lang.String, java.lang.String) Intent.setClassName()}
with the recipient's class name. The recipient receives a {@link android.content.Context
Context} object that refers to its own package, not to the package of the sender.</p>
<p><em><strong>Note:</strong></em>&nbsp;&nbsp;&nbsp;If a receiver or broadcaster
enforces permissions, your application might need to request permission
to send or receive messages from that object. You can request permission by using
the &lt;uses-permission&gt; tag in the manifest. </p>
<p>Here is a code snippet of a sender and receiver. This example does not demonstrate
registering receivers dynamically. For a full code example, see the AlarmService
class in the ApiDemos project.</p>
<h3>Sending the message</h3>
<pre>// We are sending this to a specific recipient, so we will
// only specify the recipient class name.
Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra(&quot;message&quot;,&quot;Wake up.&quot;);
sendBroadcast(intent);
</pre>
<h3>Receiving the message</h3>
<p><strong>Receiver AndroidManifest.xml </strong>(because there is no intent filter
child, this class will only receive a broadcast when the receiver class is specified
by name, as is done in this example):</p>
<pre>
&lt;receiver class=".AlarmReceiver" /&gt;</pre>
<p><strong>Receiver Java code: </strong></p>
<pre>
public class AlarmReceiver extends BroadcastReceiver{
// Display an alert that we've received a message.
&#064;Override
public void onReceive(Context context, Intent intent){
// Send a text notification to the screen.
NotificationManager nm = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notifyWithText(R.id.alarm,
&quot;Alarm!!!&quot;,
NotificationManager.LENGTH_SHORT,
null);
}
} </pre>
<h3>Other system messages</h3>
<p>You can listen for other system messages sent by Android as well, such as USB
connection/removal messages, SMS arrival messages, and timezone changes. See
{@link android.content.Intent} for a list of broadcast messages to listen for.
Messages are marked &quot;Broadcast Action&quot; in the documentation. </p>
<h3>Listening for phone events<a name="phoneevents" id="phoneevents"></a></h3>
<p>The {@link android.telephony android.telephony} package overview page describes how to
register to listen for phone events. </p>
<a name="alarms" id="alarms"></a><h3>Setting Alarms </h3>
<p>Android provides an {@link android.app.AlarmManager AlarmManager} service that
will let you specify an Intent to send at a designated time. This intent is typically
used to start an application at a preset time. (Note: If you want to send
a notification to a sleeping or running application, use {@link android.os.Handler
Handler} instead.)</p>
<a name="alerts" id="alerts"></a><h2>Displaying Alerts</h2>
<p>There are two major kinds of alerts that you may display to the user:
(1) Normal alerts are displayed in response to a user action, such as
trying to perform an action that is not allowed. (2) Out-of-band alerts,
called notifications, are
displayed as a result of something happening in the background, such as the
user receiving new e-mail.</p>
<a name="dialogsandalerts" id="dialogsandalerts"></a><h3>Normal Alerts</h3>
<p>Android provides a number of ways for you to show popup notifications to your
user as they interact with your application. </p>
<table width="100%" border="1">
<tr>
<th scope="col">Class</th>
<th scope="col">Description</th>
</tr>
<tr>
<td>{@link android.app.Dialog app.Dialog}</td>
<td>A generic floating dialog box with a layout that you design. </td>
</tr>
<tr>
<td><p>{@link android.app.AlertDialog app.AlertDialog}</p></td>
<td>A popup alert dialog with two buttons (typically OK and Cancel) that
take callback handlers. See the section after this table for more details. </td>
</tr>
<tr>
<td>{@link android.app.ProgressDialog ProgressDialog} </td>
<td>A dialog box used to indicate progress of an operation with a known progress
value or an indeterminate length (setProgress(bool)). See <strong>Views</strong> &gt; <strong>Progress Bar</strong> in
ApiDemos for examples. </td>
</tr>
<tr>
<td>Activity</td>
<td>By setting the theme of an activity to
{@link android.R.style#Theme_Dialog
android:theme=&quot;&#064;android:style/Theme.Dialog&quot;},
your activity will take on
the appearance of a normal dialog, floating on top of whatever was
underneath it. You usually set the theme through the
{@link android.R.attr#theme android:theme} attribute in your AndroidManifest.xml.
The advantage of this
over Dialog and AlertDialog is that Application has a much better managed
life cycle than dialogs: if a dialog goes to the background and is killed,
you cannot recapture state, whereas Application exposes a {@link android.os.Bundle
Bundle} of saved values in <code>onCreate()</code> to help you maintain state.</td>
</tr>
</table>
<h3>AlertDialog</h3>
<p>This is a basic warning dialog box that lets you configure a message, button text,
and callback. You can create one by calling using the {@link
android.app.AlertDialog.Builder} class, as shown here. </p>
<pre>private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case ACCEPT_CALL:
answer(msg.obj);
break;
case BOUNCE_TO_VOICEMAIL:
voicemail(msg.obj);
break;
}
}
};
private void IncomingMotherInLawCall(Connection c) {
String Text;
// &quot;Answer&quot; callback.
Message acceptMsg = Message.obtain();
acceptMsg.target = mHandler;
acceptMsg.what = ACCEPT_CALL;
acceptMsg.obj = c.getCall();
// &quot;Cancel&quot; callback.
final Message rejectMsg = Message.obtain();
rejectMsg.target = mHandler;
rejectMsg.what = BOUNCE_TO_VOICEMAIL;
rejectMsg.obj = c.getCall();
new AlertDialog.Builder(this)
.setMessage("Phyllis is calling")
.setPositiveButton("Answer", acceptMsg)
.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface dialog) {
rejectMsg.sendToTarget();
}});
.show();
} </pre>
<h3>Notifications</h3>
<p>Out-of-band alerts should always be displayed using the
{@link android.app.NotificationManager}, which allows you to tell the user
about something they may be interested in without disrupting what they are
currently doing. A notification can be anything from a brief pop-up box
informing the user of the new information, through displaying a persistent
icon in the status bar, to vibrating, playing sounds, or flashing lights to
get the user's attention. In all cases, the user must explicitly shift their
focus to the notification before they can interact with it.</p>
<p>The following code demonstrates using NotificationManager to display a basic text
popup when a new SMS message arrives in a listening service, and provides the
current message count. You can see several more examples in the ApiDemos application,
under app/ (named <em>notification</em>*.java).</p>
<pre>static void setNewMessageIndicator(Context context, int messageCount){
// Get the static global NotificationManager object.
NotificationManager nm = NotificationManager.getDefault();</p>
// If we're being called because a new message has been received,
// then display an icon and a count. Otherwise, delete the persistent
// message.
if (messageCount &gt; 0) {
nm.notifyWithText(myApp.NOTIFICATION_GUID, // ID for this notification.
messageCount + &quot; new message&quot; + messageCount &gt; 1 ? &quot;s&quot;:&quot;&quot;, // Text to display.
NotificationManager.LENGTH_SHORT); // Show it for a short time only.
}
}</pre>
<p>To display a notification in the status bar and have it launch an intent when
the user selects it (such as the new text message notification does), call {@link
android.app.NotificationManager#notify(int, android.app.Notification) NotificationManager.notify()},
and pass in vibration patterns, status bar icons, or Intents to associate with
the notification. </p>
<a name="progressbar" id="progressbar"></a><h2>Displaying a Progress Bar</h2>
<p>An activity can display a progress bar to notify the user that something is happening.
To display a progress bar in a screen, call {@link android.app.Activity#requestWindowFeature(int)
Activity.requestWindowFeature(Window.FEATURE_PROGRESS)}. To set the value
of the progress bar, call {@link android.view.Window#setFeatureInt(int,int)
Activity.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, <em>level</em>)}.
Progress bar values are from 0 to 9,999, or set the value to 10,000 to make the
progress bar invisible. </p>
<p>You can also use the {@link android.app.ProgressDialog ProgressDialog} class,
which enables a dialog box with an embedded progress bar to send a &quot;I'm working
on it&quot; notification to the user. </p>
<a name="addmenuitems" id="addmenuitems"></a><h2>Adding Items to the Screen Menu</h2>
<p>See <a href="{@docRoot}guide/topics/ui/menus.html">Creating Menus</a>.</p>
<a name="webpage" id="webpage"></a><h2>Display a Web Page</h2>
<p>Use the {@link android.webkit.WebView webkit.WebView} object. </p>
<a name="binding" id="binding"></a><h2>Binding to Data</h2>
<p>You can bind a ListView to a set of underlying data by using a shim class called
{@link android.widget.ListAdapter ListAdapter} (or a subclass). ListAdapter subclasses
bind to a variety of data sources, and expose a common set of methods such as
getItem() and getView(), and uses them to pick View items to display in its list.
You can extend ListAdapter and override getView() to create your own custom list
items. There are essentially only two steps you need to perform to bind to data: </p>
<ol>
<li>Create a ListAdapter object and specify its data source</li>
<li>Give the ListAdapter to your ListView object.</li>
</ol>
<p>That's it!</p>
<p>Here's an example of binding a ListActivity screen to the results from a cursor
query. (Note that the setListAdapter() method shown is a convenience method that
gets the page's ListView object and calls setAdapter() on it.)</p>
<pre>// Run a query and get a Cursor pointing to the results.
Cursor c = People.query(this.getContentResolver(), null);
startManagingCursor(c);
// Create the ListAdapter. A SimpleCursorAdapter lets you specify two interesting things:
// an XML template for your list item, and
// The column to map to a specific item, by ID, in your template.
ListAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, // Use a template that displays a text view
c, // Give the cursor to the list adapter
new String[] {People.NAME} , // Map the NAME column in the people database to...
new String[] {"text1"}); // The "text1" view defined in the XML template
setListAdapter(adapter);</pre>
<p>See view/List4 in the ApiDemos project for an example of extending ListAdapter
for a new data type. </p>
<a name="handle"></a>
<h2>Getting a Handle to a Screen Element</h2>
<p>You can get a handle to a screen element by calling {@link
android.app.Activity#findViewById(int) Activity.findViewById}. You can then use
the handle to set or retrieve any values exposed by the object. </p>
<a name="captureimages" id="captureimages"></a><h2>Capture Images from the Phone Camera</h2>
<p>You can hook into the device's camera onto your own Canvas object by using the
{@link android.hardware.Camera Camera} class. See that class's documentation,
and the ApiDemos project's Camera Preview application (Graphics/Camera Preview)
for example code. </p>
<a name="threading" id="threading"></a><h2>Handling Expensive Operations in the UI Thread</h2>
<p>Avoid performing long-running operations (such as network I/O) directly in the UI thread &mdash;
the main thread of an application where the UI is run &mdash; or your application may be blocked
and become unresponsive. Here is a brief summary of the recommended approach for handling expensive operations:</p>
<ol>
<li>Create a Handler object in your UI thread</li>
<li>Spawn off worker threads to perform any required expensive operations</li>
<li>Post results from a worker thread back to the UI thread's handler either through a Runnable or a {@link android.os.Message}</li>
<li>Update the views on the UI thread as needed</li>
</ol>
<p>The following outline illustrates a typical implementation:</p>
<pre>
public class MyActivity extends Activity {
[ . . . ]
// Need handler for callbacks to the UI thread
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
updateResultsInUi();
}
};
&#64;Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
[ . . . ]
}
protected void startLongRunningOperation() {
// Fire off a thread to do some work that we shouldn't do directly in the UI thread
Thread t = new Thread() {
public void run() {
mResults = doSomethingExpensive();
mHandler.post(mUpdateResults);
}
};
t.start();
}
private void updateResultsInUi() {
// Back in the UI thread -- update our UI elements based on the data in mResults
[ . . . ]
}
}
</pre>
<p>For further discussions on this topic, see
<a href="{@docRoot}guide/practices/design/responsiveness.html">Designing for Responsiveness</a>
and the {@link android.os.Handler} documentation.</p>
<a name="selectingtext" id="selectingtext"></a><h2>Selecting, Highlighting, or Styling Portions of Text</h2>
<p>You can highlight or style the formatting of strings or substrings of text in
a TextView object. There are two ways to do this:</p>
<ul>
<li>If you use a <a href="{@docRoot}guide/topics/resources/available-resources.html#stringresources">string resource</a>,
you can add some simple styling, such as bold or italic using HTML notation.
The currently supported tags are: <code>B</code> (bold),
<code>I</code> (italic), <code>U</code> (underline),
<code>TT</code> (monospace), <code>BIG</code>, <code>SMALL</code>,
<code>SUP</code> (superscript), <code>SUB</code> (subscript),
and <code>STRIKE</code> (strikethrough).
So, for example, in res/values/strings.xml you could declare this:<br />
<code>&lt;resource&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;string&nbsp;id=&quot;@+id/styled_welcome_message&quot;&gt;We
are &lt;b&gt;&lt;i&gt;so&lt;/i&gt;&lt;/b&gt; glad to see you.&lt;/string&gt;<br />
&lt;/resources&gt;</code></li>
<li>To style text on the fly, or to add highlighting or more complex styling,
you must use the Spannable object as described next. </li>
</ul>
<p>To style text on the fly, you must make sure the TextView is using {@link android.text.Spannable}
storage for the text (this will always be true if the TextView is an EditText),
retrieve its text with {@link android.widget.TextView#getText}, and call {@link
android.text.Spannable#setSpan}, passing in a new style class from the {@link
android.text.style} package and the selection range. </p>
<p>The following code snippet demonstrates creating a string with a highlighted section,
italic section, and bold section, and adding it to an EditText object. </p>
<pre>// Get our EditText object.
EditText vw = (EditText)findViewById(R.id.text);
// Set the EditText's text.
vw.setText("Italic, highlighted, bold.");
// If this were just a TextView, we could do:
// vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE);
// to force it to use Spannable storage so styles can be attached.
// Or we could specify that in the XML.
// Get the EditText's internal text storage
Spannable str = vw.getText();
// Create our span sections, and assign a format to each.
str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
</pre>
<a name="querymap" id="querymap"></a><h2>Utilizing attributes in a Map query</h2>
<p>
When using a search intent to ask the Maps activity to search for something, the Maps activity responds to the following attributes in the optional context bundle:
</p>
<pre>
float "centerLatitude" default 0.0f
float "centerLongitude" default 0.0f
float "latitudeSpan" default 0.0f
float "longitudeSpan" default 0.0f
int "zoomLevel" default 10
</pre>
<p>
This context information is used to center the search result in a particular area, and is equivalent to adjusting the Map activity to the described location and zoom level before issuing the query.
</p>
<p>
If the latitudeSpan, longitudeSpan, and zoomLevel attributes are not consistent, then it is undefined which one takes precedence.
</p>
<a name="filelist" id="filelist"></a><h2>List of Files for an Android Application</h2>
<p>The following list describes the structure and files of an Android application.
Many of these files can be built for you (or stubbed out) by the android tool
shipped in the tools/ menu of the SDK. </p>
<table width="100%" border="0">
<tr>
<td width="28%" valign="top">MyApp/<br /></td>
<td width="72%" valign="top">&nbsp;</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;AndroidManifest.xml</td>
<td valign="top">(<em>required</em>) Advertises the screens that this application provides,
where they can be launched (from the main program menu or elsewhere),
any content providers it implements and what kind of data they handle,
where the implementation classes are, and other application-wide
information. Syntax details for this file are described in <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml File</a>.</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;src/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<em>myPackagePath</em>/.../<em>MyClass</em>.java</td>
<td valign="top">(<em>required</em>) This folder holds all the source code files for your
application, inside the appropriate package subfolders. </td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;res/</td>
<td valign="top">(<em>required</em>) This folder holds all the <em>resources</em> for
your application. Resources are external data files or description files
that are compiled into your code at build time. Files in different folders
are compiled differently, so you must put the proper resource into the
proper folder. (See <a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a> for details.)</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;anim/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>animation1</em>.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>...</em></td>
<td valign="top">(<em>optional</em>) Holds any animation XML description files that the
application uses. The format of these files is described in <a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a>. </td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;drawable/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>some_picture</em>.png<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>some_stretchable</em>.9.png<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>some_background</em>.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</td>
<td valign="top">(<em>optional</em>) Zero or more files that will be compiled to {@link
android.graphics.drawable android.graphics.drawable} resources. Files
can be image files (png, gif, or other) or XML files describing other
graphics such as bitmaps, stretchable bitmaps, or gradients. Supported
bitmap file formats are PNG (preferred), JPG, and GIF (discouraged),
as well as the custom 9-patch stretchable bitmap format. These formats
are described in <a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a>. </td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layout/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>screen_1_layout</em>.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br /></td>
<td valign="top">(<em>optional</em>) Holds all the XML files describing screens or parts
of screens. Although you could create a screen in Java, defining them
in XML files is typically easier. A layout file is similar in concept
to an HTML file that describes the screen layout and components. See <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> for more information about designing screens, and <a href="{@docRoot}guide/topics/resources/available-resources.html#layoutresources">Available Resource Types</a> for the syntax of these files.</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arrays<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;classes.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;colors.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dimens.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strings.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;styles.xml<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values.xml<br /></td>
<td valign="top"><p>(<em>optional</em>) XML files describing additional resources
such as strings, colors, and styles. The naming, quantity, and number
of these files are not enforced--any XML file is compiled, but these
are the standard names given to these files. However, the syntax
of these files is prescribed by Android, and described in <a href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a>. </p>
</td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xml/</td>
<td valign="top">(<em>optional</em>) XML files that can be read at run time on the device. </td>
</tr>
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raw/</td>
<td valign="top">(<em>optional</em>) Any files to be copied directly to the device. </td>
</tr>
</table>
<a name="logging" ></a>
<h2>Print Messages to a Log File</h2>
<p>To write log messages from your application:</p>
<ol><li>Import <code>android.util.Log</code>.</li>
<li>Use <code>Log.v()</code>, <code>Log.d()</code>, <code>Log.i()</code>,
<code>Log.w()</code>, or <code>Log.e()</code> to log messages.
(See the {@link android.util.Log} class.)<br/> E.g.,
<code>Log.e(this.toString(), "error: " + err.toString())</code></li>
<li>Launch <a href="{@docRoot}guide/developing/tools/ddms.html">DDMS</a> from a terminal
by executing <code>ddms</code> in your Android SDK <code>/tools</code> path.</li>
<li>Run your application in the Android emulator.</li>
<li>From the DDMS application, select the emulator
(e.g., "emulator-5554") and click <b>Device > Run logcat...</b>
to view all the log data.</li>
</ol>
<p class="note"><strong>Note:</strong> If you are running Eclipse and
encounter a warning about the VM debug port when opening DDMS, you can ignore it
if you're only interested in logs. However, if you want to further inspect and
control your processes from DDMS, then you should close Eclipse before launching DDMS so that
it may use the VM debugging port.</p>
@@ -0,0 +1,197 @@
page.title=Android Application Framework FAQ
parent.title=FAQs, Tips, and How-to
parent.link=index.html
@jd:body
<ul>
<li><a href="#1">Do all the Activities and Services of an
application run in a single process?</a></li>
<li><a href="#2">Do all Activities run in the main thread of
an application process?</a></li>
<li><a href="#3">How do I pass complicated data structures
from one Activity/Service to another?</a></li>
<li><a href="#4">How can I check if an Activity is already
running before starting it?</a></li>
<li><a href="#5">If an Activity starts a remote service, is
there any way for the Service to pass a message back to the Activity?</a></li>
<li><a href="#6">How to avoid getting the Application not
responding dialog?</a></li>
<li><a href="#7">How does an application know if a package is
added or removed?</a></li>
</ul>
<a name="1" id="1"></a>
<h2>Do all the Activities and Services of an application run in a
single process?</h2>
<p>All Activities and Services in an application run in a single process by
default. If needed, you can declare an <code>android:process</code> attribute
in your manifest file, to explicitly place a component (Activity/Service) in
another process.</p>
<a name="2" id="2"></a>
<h2>Do all Activities run in the main thread of an application
process?</h2>
<p>By default, all of the application code in a single process runs
in the main UI thread. This is the same thread
that also handles UI events. The only exception is the code that handles
IPC calls coming in from other processes. The system maintains a
separate pool of transaction threads in each process to dispatch all
incoming IPC calls. The developer should create separate threads for any
long-running code, to avoid blocking the main UI thread.</p>
<a name="3" id="3"></a>
<h2>How do I pass data between Activities/Services within a single
application?</h2>
<p>It depends on the type of data that you want to share:</p>
<h3>Primitive Data Types</h3>
<p>To share primitive data between Activities/Services in an
application, use Intent.putExtras(). For passing primitive data that
needs to persist use the
<a href="{@docRoot}guide/topics/data/data-storage.html#preferences">
Preferences</a> storage mechanism.</p>
<h3>Non-Persistent Objects</h3>
<p>For sharing complex non-persistent user-defined objects for short
duration, the following approaches are recommended:
</p>
<h4>The android.app.Application class</h4>
<p>The android.app.Application is a base class for those who need to
maintain global application state. It can be accessed via
getApplication() from any Activity or Service. It has a couple of
life-cycle methods and will be instantiated by Android automatically if
your register it in AndroidManifest.xml.</p>
<h4>A public static field/method</h4>
<p>An alternate way to make data accessible across Activities/Services is to use <em>public static</em>
fields and/or methods. You can access these static fields from any other
class in your application. To share an object, the activity which creates your object sets a
static field to point to this object and any other activity that wants to use
this object just accesses this static field.</p>
<h4>A HashMap of WeakReferences to Objects</h4>
<p>You can also use a HashMap of WeakReferences to Objects with Long
keys. When an activity wants to pass an object to another activity, it
simply puts the object in the map and sends the key (which is a unique
Long based on a counter or time stamp) to the recipient activity via
intent extras. The recipient activity retrieves the object using this
key.</p>
<h4>A Singleton class</h4>
<p>There are advantages to using a static Singleton, such as you can
refer to them without casting getApplication() to an
application-specific class, or going to the trouble of hanging an
interface on all your Application subclasses so that your various
modules can refer to that interface instead. </p>
<p>But, the life cycle of a static is not well under your control; so
to abide by the life-cycle model, the application class should initiate and
tear down these static objects in the onCreate() and onTerminate() methods
of the Application Class</p>
</p>
<h3>Persistent Objects</h3>
<p>Even while an application appears to continue running, the system
may choose to kill its process and restart it later. If you have data
that you need to persist from one activity invocation to the next, you
need to represent that data as state that gets saved by an activity when
it is informed that it might go away.</p>
<p>For sharing complex persistent user-defined objects, the
following approaches are recommended:
<ul>
<li>Application Preferences</li>
<li>Files</li>
<li>contentProviders</li>
<li>SQLite DB</li>
</ul>
</p>
<p>If the shared data needs to be retained across points where the application
process can be killed, then place that data in persistent storage like
Application Preferences, SQLite DB, Files or ContentProviders. Please refer to
the <a href="{@docRoot}guide/topics/data/data-storage.html">Data Storage</a>
for further details on how to use these components.</p>
<a name="4" id="4"></a>
<h2>How can I check if an Activity is already running before starting
it?</h2>
<p>The general mechanism to start a new activity if its not running&mdash;
or to bring the activity stack to the front if is already running in the
background&mdash; is the to use the NEW_TASK_LAUNCH flag in the startActivity()
call.</p>
<a name="5" id="5"></a>
<h2>If an Activity starts a remote service, is there any way for the
Service to pass a message back to the Activity?</h2>
<p>The remote service can define a callback interface and register it with the
clients to callback into the clients. The
{@link android.os.RemoteCallbackList RemoteCallbackList} class provides methods to
register and unregister clients with the service, and send and receive
messages.</p>
<p>The sample code for remote service callbacks is given in <a
href="{@docRoot}guide/samples/ApiDemos/src/com/example/android/apis/app/RemoteService.html">ApiDemos/RemoteService</a></p>
<a name="6" id="6"></a>
<h2>How to avoid getting the Application not responding dialog?</h2>
<p>Please read the <a href="{@docRoot}guide/practices/design/responsiveness.html">Designing for Responsiveness</a>
document.</p>
<a name="7" id="7"></a>
<h2>How does an application know if a package is added or removed?
</h2>
<p>Whenever a package is added, an intent with PACKAGE_ADDED action
is broadcast by the system. Similarly when a package is removed, an
intent with PACKAGE_REMOVED action is broadcast. To receive these
intents, you should write something like this:
<pre>
&lt;receiver android:name ="com.android.samples.app.PackageReceiver"&gt;
&lt;intent-filter&gt;
&lt;action android:name="android.intent.action.PACKAGE_ADDED"/&gt;
&lt;action android:name="android.intent.action.PACKAGE_REMOVED"/&gt;
&lt;data android:scheme="package" /&gt;
&lt;/intent-filter&gt;
&lt;/receiver&gt;
</pre>
<br>
Here PackageReceiver is a BroadcastReceiver class.Its onReceive()
method is invoked, every time an application package is installed or
removed.
</p>
@@ -0,0 +1,15 @@
page.title=FAQs, Tips, and How-to
@jd:body
<dl>
<dt><a href="commontasks.html">Common Development Tasks and How To Do Them</a></dt>
<dd>Quick and to the point &mdash; how-to's for a variety of development tasks you are likely to use.</dd>
<dt><a href="framework.html">Application Framework FAQ</a></dt>
<dd>Common questions about the Android Application Framework.</dd>
<dt><a href="troubleshooting.html">Troubleshooting Tips</a></dt>
<dd>Answers to help you troubleshoot common problems.</dd>
<dt><a href="licensingandoss.html">Open Source Licensing FAQ</a></dt>
<dd>Common topics around licensing and Android Open Source</dd>
<dt><a href="security.html">Android Security FAQ</a></dt>
<dd>Answers to common questions about Android security.</dd>
</dl>
@@ -0,0 +1,19 @@
page.title=Android Open Source Licensing FAQ
parent.title=FAQs, Tips, and How-to
parent.link=index.html
@jd:body
<ul>
<li><a href="#mirror">Where can I find the open source components of Android?</a></li>
<li><a href="#timeline">When will we see more code released under open source licenses?</a></li>
<li><a href="#apache2">Why are you releasing the code under the Apache License instead of GPLv2?</a></li>
</ul>
<a name="mirror" id="mirror"></a><h2>Where can I find the open source components of Android?</h2>
<p>The source code for the full Android stack is available from the <a href="http://source.android.com">Android Open Source Project </a> site.
<p>Other mirrored GPL and LGPL'd components are available at <a href="http://code.google.com/p/android/downloads/list"><code>http://code.google.com/p/android/downloads/list</code></a>.</p>
<p>Notices for other licenses can be found within the SDK.</p>
<a name="apache2" id="apache2"></a><h2>Why are you releasing the code under the Apache License instead of GPLv2?</h2>
<p>One of the best explanations for the reasoning behind releasing code under Apache2 can be found in a <a href="http://arstechnica.com/news.ars/post/20071106-why-google-chose-the-apache-software-license-over-gplv2.html">ArsTechnica article</a> by Ryan Paul.</p>
@@ -0,0 +1,156 @@
page.title=Android Security FAQ
parent.title=FAQs, Tips, and How-to
parent.link=index.html
@jd:body
<ul>
<li><a href="#secure">Is Android Secure?</a></li>
<li><a href="#issue">I think I found a security flaw. How do I report
it?</a></li>
<li><a href="#informed">How can I stay informed of Android security
announcements?</a></li>
<li><a href="#use">How do I securely use my Android phone?</a></li>
<li><a href="#malware">I think I found malicious software being distributed
for Android. How can I help?</a></li>
<li><a href="#fixes">How will Android-powered devices receive security fixes?</a>
</li>
<li><a href="#directfix">Can I get a fix directly from the Android Platform
Project?</a></li>
</ul>
<a name="secure" id="secure"></a><h2>Is Android secure?</h2>
<p>The security and privacy of our users' data is of primary importance to the
Android Open Source Project. We are dedicated to building and maintaining one
of the most secure mobile platforms available while still fulfilling our goal
of opening the mobile device space to innovation and competition.</p>
<p>The Android Platform provides a rich <a
href="http://code.google.com/android/devel/security.html">security model</a>
that allows developers to request the capabilities, or access, needed by their
application and to define new capabilities that other applications can request.
The Android user can choose to grant or deny an application's request for
certain capabilities on the handset.</p>
<p>We have made great efforts to secure the Android platform, but it is
inevitable that security bugs will be found in any system of this complexity.
Therefore, the Android team works hard to find new bugs internally and responds
quickly and professionally to vulnerability reports from external researchers.
</p>
<a name="issue" id="issue"></a><h2>I think I found a security flaw. How do I
report it?</h2>
<p>You can reach the Android security team at <a
href="mailto:security@android.com">security@android.com</a>. If you like, you
can protect your message using our <a
href="http://code.google.com/android/security_at_android_dot_com.txt">PGP
key</a>.</p>
<p>We appreciate researchers practicing responsible disclosure by emailing us
with a detailed summary of the issue and keeping the issue confidential while
users are at risk. In return, we will make sure to keep the researcher informed
of our progress in issuing a fix and will properly credit the reporter(s) when
we announce the patch. We will always move swiftly to mitigate or fix an
externally-reported flaw and will publicly announce the fix once patches are
available to users.</p>
<a name="informed" id="informed"></a><h2>How can I stay informed of Android
security announcements?</h2>
<p>An important part of sustainably securing a platform, such as, Android is
keeping the user and security community informed of bugs and fixes. We will
publicly announce security bugs when the fixes are available via postings to
the <a
href="http://groups.google.com/group/android-security-announce">android-security-announce</a>
group on Google Groups. You can subscribe to this group as you would a mailing
list and view the archives here.</p>
<p>For more general discussion of Android platform security, or how to use
security features in your Android application, please subscribe to <a
href="http://groups.google.com/group/android-security-discuss">android-security-discuss</a>.
</p>
<a name="use" id="use"></a><h2>How do I securely use my Android phone?</h2>
<p>As an open platform, Android allows users to load software from any
developer onto a device. As with a home PC, the user must be
aware of who is providing the software they are downloading and must decide
whether they want to grant the application the capabilities it requests.
This decision can be informed by the user's judgment of the software
developer's trustworthiness, and where the software came from.</p>
<p>Despite the security protections in Android, it is important
for users to only download and install software from developers they trust.
More details on how Android users can make smart security decisions will be
released when consumer devices become available.</p>
<a name="malware" id="malware"></a><h2>I think I found malicious software being
distributed for Android. How can I help?</h2>
<p>Like any other open platform, it will be possible for unethical developers
to create malicious software, known as <a
href="http://en.wikipedia.org/wiki/Malware">malware</a>, for Android. If you
think somebody is trying to spread malware, please let us know at <a
href="mailto:security@android.com">security@android.com</a>. Please include as
much detail about the application as possible, with the location it is
being distributed from and why you suspect it of being malicious software.</p>
<p>The term <i>malicious software</i> is subjective, and we cannot make an
exhaustive definition. Some examples of what the Android Security Team believes
to be malicious software is any application that:
<ul>
<li>drains the device's battery very quickly;</li>
<li>shows the user unsolicited messages (especially messages urging the
user to buy something);</li>
<li>resists (or attempts to resist) the user's effort to uninstall it;</li>
<li>attempts to automatically spread itself to other devices;</li>
<li>hides its files and/or processes;</li>
<li>discloses the user's private information to a third party, without the
user's knowledge and consent;</li>
<li>destroys the user's data (or the device itself) without the user's
knowledge and consent;</li>
<li>impersonates the user (such as by sending email or buying things from a
web store) without the user's knowledge and consent; or</li>
<li>otherwise degrades the user's experience with the device.</li>
</ul>
</p>
<a name="fixes" id="fixes"></a><h2>How will Android-powered devices receive security
fixes?</h2>
<p>The manufacturer of each device is responsible for distributing software
upgrades for it, including security fixes. Many devices will update themselves
automatically with software downloaded "over the air", while some devices
require the user to upgrade them manually.</p>
<p>When Android-powered devices are publicly available, this FAQ will provide links how
Open Handset Alliance members release updates.</p>
<a name="directfix" id="directfix"></a><h2>Can I get a fix directly from the
Android Platform Project?</h2>
<p>Android is a mobile platform that will be released as open source and
available for free use by anybody. This means that there will be many
Android-based products available to consumers, and most of them will be created
without the knowledge or participation of the Android Open Source Project. Like
the maintainers of other open source projects, we cannot build and release
patches for the entire ecosystem of products using Android. Instead, we will
work diligently to find and fix flaws as quickly as possible and to distribute
those fixes to the manufacturers of the products.</p>
<p>In addition, We will add security fixes to the open source distribution of
Android and publicly announce the changes on <a
href="http://groups.google.com/group/android-security-announce">android-security-announce</a>.
</p>
<p>If you are making an Android-powered device and would like to know how you can
properly support your customers by keeping abreast of software updates, please
contact us at <a
href="mailto:info@openhandsetalliance.com">info@openhandsetalliance.com</a>.</p>
+335
View File
@@ -0,0 +1,335 @@
page.title=Troubleshooting
parent.title=FAQs, Tips, and How-to
parent.link=index.html
@jd:body
<p>Here are some tips and tricks for common Android errors. Don't forget to use the
ddms logcat capability to get a deeper view when errors occur. See <a href="{@docRoot}guide/developing/debug-tasks.html">Debugging</a> for more debugging tips. </p>
<ul>
<li><a href="#installeclipsecomponents">ADT Installation Error: "requires plug-in org.eclipse.wst.sse.ui".</a></li>
<li><a href="#nodevice">ADB reports &quot;no device&quot; when an emulator is running</a></li>
<li><a href="#noapp">My new application/activity isn't showing up in the device application
list </a></li>
<li><a href="#noupdate">I updated my app, but the updates don't seem to be showing up on
the device</a></li>
<li><a href="#layout_wilih">I'm getting a &quot;Binary XML file line #2: You must supply a layout_wilih
attribute&quot; error when I start an application</a></li>
<li><a href="#permission">My request to (<em>make a call, catch an incoming SMS, receive
a notification, send an intent to an Android application</em>) is being
ignored</a></li>
<li><a href="#build">Help! My project won't build in Eclipse</a></li>
<li><a href="#eclipse">Eclipse isn't talking to the emulator</a></li>
<li><a href="#majorminor">When I go to preferences in Eclipse and select "Android", I get the following error message: Unsupported major.minor version 49.0.</a></li>
<li><a href="#apidemosreinstall">I can't install ApiDemos apps in my IDE because of a signing error</a></li>
<li><a href="#gesturebuilderinstall">I can't install the GestureBuilder sample
app in the emulator</a></li>
<li><a href="#signingcalendar">I can't compile my app because the build tools generated an expired debug certificate</a></li>
<li><a href="#manifestfiles">Unable to view manifest files from within Eclipse</a></li>
</ul>
<a name="installeclipsecomponents" id="installeclipsecomponents"></a><h2>ADT Installation Error: "requires plug-in org.eclipse.wst.sse.ui".</h2>
<p>
The "Android Editors" feature of the ADT Plugin requires specific Eclipse components, such as WST. If you
encounter this error message during ADT installation, you need to install the
required Eclipse components and then try the ADT installation again. Follow the steps below to install the required components for the
Android Editors feature, based on the version of Eclipse that you are using.</p>
<table style="font-size:100%">
<tr><th>Eclipse 3.3 (Europa)</th><th>Eclipse 3.4 (Ganymede)</th></tr>
<tr>
<td width="50%">
<ol>
<li>From the dialog where you select the <strong>Update sites to visit</strong>, select the checkboxes for both the
ADT site, and the Callisto/Europa/Ganymede Discovery Site (you may want to
check <strong>Automatically select mirrors</strong> at the bottom).</li>
<li>Click <strong>Finish</strong>.</li>
<li>In the <strong>Next</strong> dialog, select the Android Plugins.</li>
<li>Now, expand the tree item of the discovery site. It seems that if you
don't do it, it doesn't load the content of the discovery site.</li>
<li>On the right, click <strong>Select required</strong>. This will select all the components
that are required to install the Android plugin (wst, emf, etc...).</li>
<li>Click <strong>Next</strong>, accept the agreement, click <strong>Install All</strong>, and restart Eclipse.</li>
</ol>
</td>
<td>
<ol>
<li>Select <strong>Help</strong> &gt; <strong>Software Updates...</strong></li>
<li>Select the <strong>Installed Software</strong> tab.</li>
<li>Click <strong>Update...</strong></li>
<li>If an update for ADT is available, select it and click <strong>Finish</strong>.</li>
</ol>
</td>
</tr>
</table>
</p>
<a name="nodevice"></a><h2>ADB reports &quot;no device&quot; when an emulator is running</h2>
<p>Try restarting adb by stopping it (<code>adb
kill-server</code>) then any other adb command to restart it.</p>
<a name="noapp"></a><h2>My new application/activity isn't showing up in the
applications list </h2>
<ul>
<li>You often must restart your device or emulator before a new activity shows
up in the applications list. This is particularly true when it is a completely
new application with a new AndroidManifest.xml file.</li>
<li>If this is for a new activity in an existing AndroidManifest.xml file, did
you include an <code>&lt;activity&gt;</code> tag for your app (or a <code>&lt;service&gt;</code> tag
for a service, or a <code>&lt;receiver&gt;</code> tag for a receiver, etc.)? </li>
<li>Make sure that your AndroidManifest.xml file is valid. Errors in attribute
values, such as the <em>value </em> attribute in <code>&lt;action <em>value</em>=&quot;<em>&lt;something&gt;</em>&quot;&gt;</code>
will often not be caught by compilers, but will prevent your application
from being displayed because the intent filter will not be matched. Extra
spaces or other characters can often sneak into these strings.</li>
<li>Did you send your .apk file to the device (<a href="{@docRoot}guide/developing/tools/adb.html#move">adb install</a>)?</li>
<li>Run logcat on your device (<code>adb logcat</code>)
and then install your .apk file. Check the logcat output to see whether the
application is being installed and recognized properly. Here's sample output
from a successful installation:
<pre>I/FileObserver( 414): *** onEvent wfd: 3 mask: 8 path: MyRSSReader.apk
D/PackageManager( 414): Scanning package: /data/app/MyRSSReader.apk
D/PackageManager( 414): Adding package com.example.codelab.rssexample
D/PackageManager( 414): Registered content provider: my_rss_item, className = com.example.codelab.rssexample.RssContentProvider, isSyncable = false
D/PackageManager( 414): Providers: com.example.codelab.rssexample.RssContentProvider
D/PackageManager( 414): Activities: com.example.codelab.rssexample.MyRssReader com.example.codelab.rssexample.MyRssReader2 </pre>
</li>
<li>If logcat shows that the package manager is having problems loading the manifest
file, force your manifest to be recompiled by adding a space in the file and
compiling it.</li>
</ul>
<a name="noupdate"></a><h2>I updated my app, but the updates don't seem to be showing up on the device</h2>
<p>Did you remember to send your .apk file to the device (<a href="{@docRoot}guide/developing/tools/adb.html#move">adb
install</a>)?</p>
<a name="layout_wilih"></a><h2>I'm getting a &quot;Binary XML file line #2: You must supply a layout_wilih
attribute&quot; error
when I start an application (but I declare a layout_wilih attribute <em>right
there!!!</em>)</h2>
<ul>
<li>Make sure that the SDK you are building with is the same version as the Android
OS that you are running on. </li>
<li>Make sure that you're calling setContentView() early in your onCreate() method.
Calling other methods, such as setListAdapter() before calling setContentView()
can sometimes create odd errors when Android tries to access screen elements
that haven't been set before.</li>
</ul>
<a name="permission"></a><h2>My request to (<em>make a call, catch an incoming SMS,
receive a notification, send an intent to an Android application</em>) is being
ignored</h2>
<p>You might not have permission (or might not have requested permission) to
call this activity or receive this intent. Many standard Android activities,
such as making a call, have a permission assigned to it to prevent arbitrary
applications from sending or receiving requests. See <a
href="{@docRoot}guide/topics/security/security.html">Security and
Permissions</a> for more information on permissions, and
{@link android.Manifest.permission Manifest.permission} for a list of
standard permissions supported by the Android platform.
</p>
<a name="build"></a><h2>Help! My project won't build in Eclipse</h2>
<p>If your project doesn't build, you may notice symptoms such as new
resources added in the <code>res/</code> sub-folders not showing up in the R class,
the emulator not being started, not being able to run the application, or even seeming to run an old version of the application.</p>
<p>To troubleshoot these types of problems, first try:</p>
<ol>
<li>Switch to the DDMS view in Eclipse (if you don't already have it open):
<ol type="a">
<li>From the menu select <code>Window &gt; Open Perspective &gt; Other</code></li>
<li>Select DDMS from the list and hit OK</li>
</ol>
</li>
<li>In the Devices panel (top right panel by default), click on the down triangle
to bring up the panel menu</li>
<li>Select <code>Reset ADB</code> from the menu, and then try running the
application again</li>
</ol>
<p>If the above still doesn't work, you can try these steps:</p>
<ol>
<li>
Check the console and problems tabs at the bottom of the Eclipse UI
</li>
<li>
If there are problems listed in either place, they should give you a clue
what is wrong
</li>
<li>
If you aren't sure if the problems are fresh or stale, clear the console
with a right click &gt; Clear, then clean the project
</li>
<li>
To clean the project (a good idea with any kind of build error), select
Project &gt; Clean from the eclipse main menu, then select the project you
are working on (or clean all)
</li>
</ol>
<a name="eclipse"></a><h2>Eclipse isn't talking to the emulator</h2>
<p>When communication doesn't seem to be happening between Eclipse and the emulator, symptoms can include: nothing happening when you press run, the emulator hanging waiting
for a debugger to connect, or errors that Eclipse reports about not being able
to find the emulator or shell. By far the most common symptom is that when you press run, the emulator starts (or
is already running), but the application doesn't start.</p>
<p>
You may find any of these steps will fix the problem and with practice you
probably can figure out which one you need to do for your particular issue, but
to start with, the safest option is to run through all of them in order:</p>
<ol>
<li>
Quit the emulator if it is running
</li>
<li>
Check that any emulator processes are killed (sometimes they can hang, use ps on unix or mac, or task manager in the process view on
windows).
</li>
<li>
Quit Eclipse
</li>
<li>
From the command line, type:
<pre>adb kill-server </pre>
</li>
<li>
Start Eclipse and try again
</li>
</ol>
<a name="majorminor"></a><h2>When I go to preferences in Eclipse and select "Android", I get the following error message: Unsupported major.minor version 49.0.</h2>
<p>This error is displayed if you are using an older version of the JDK. Please make sure you are using JDK version 5 or 6.</p>
<h2 id="apidemosreinstall">I can't install ApiDemos apps in my IDE because of a signing error</a></h2>
<p>The Android system requires that all applications be signed, as described in
<a href="{@docRoot}guide/publishing/app-signing.html">Signing Your Applications</a>. The ApiDemos
applications included with the SDK are preinstalled on the emulator and for that reason have been
compiled and signed with a private key.</p>
If you want to modify or run one of the ApiDemos apps from Eclipse/ADT or other IDE, you can do so
so only after you uninstall the <em>preinstalled</em> version of the app from the emulator. If
you try to run an ApiDemos app from your IDE without removing the preinstalled version first,
you will get errors similar to these: </p>
<pre>[2008-08-13 15:14:15 - ApiDemos] Re-installation failed due to different application signatures.
[2008-08-13 15:14:15 - ApiDemos] You must perform a full uninstall of the application. WARNING: ...This will remove the application data!
[2008-08-13 15:14:15 - ApiDemos] Please execute 'adb uninstall com.android.samples' in a shell.</pre>
<p>The error occurs because, in this case, you are attempting to install another copy of ApiDemos
onto the emulator, a copy that is signed with a different certificate. (The Android IDE tools will
have signed the app with a debug certificate, where the existing version was already signed with
a private certificate.) The system does not allow this type of reinstallation. </p>
<p>To resolve the issue, you need to fully uninstall the preinstalled and then reinstall it using
the adb tool. Here's how to do that:</p>
<ol>
<li>In a terminal, change to the tools directory of the SDK.</li>
<li>If no emulator instance is running, start an emulator using using the command <code>emulator &</code>.</li>
<li>Uninstall the preinstalled app using the command <code>adb uninstall com.android.samples</code>.</li>
<li>Reinstall the app using the command <code>adb install &lt;path to the ApiDemos.apk&gt;</code>. If you are
working in Eclipse/ADT, you can just compile and run the app in the normal way. </li>
</ol>
<p>Note that if multiple emulator instances are running, you need to direct your uninstall/install
commands to the emulator instance that you are targeting. To do that you can add the
<code>-s &lt;serialNumber&gt;</code> to the command, for example: </p>
<pre>adb -s emulator-5556 install</pre>
<p>For more information about adb, see the <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a>
documentation.</p>
<h2 id="gesturebuilderinstall">I can't install the GestureBuilder sample
app in the emulator</a></h2>
<p>This is similar to the ApiDemos problem described above, except that
you cannot fix it by uninstalling GestureBuilder from the emulator. The
GestureBuilder app cannot be uninstalled because it is currently installed
within the system files themselves.</p>
<p><strong>Symptoms</strong></p>
<ul><li><p>You cannot run GestureBuilder in the emulator:</p>
<pre>[2009-12-10 14:57:19 - GestureBuilderActivity]Re-installation failed due to different application signatures.
[2009-12-10 14:57:19 - GestureBuilderActivity]You must perform a full uninstall of the application. WARNING: This will remove the application data!
[2009-12-10 14:57:19 - GestureBuilderActivity]Please execute 'adb uninstall com.android.gesture.builder' in a shell.</pre>
</li>
<li><p>Running <code>adb uninstall com.android.gesture.builder</code> fails:</p>
<pre>$ adb uninstall com.android.gesture.builder
Failure</pre>
</li></ul>
<p>For now, the work-around is to change the sample's package name
so that the system can install it as a new app rather than as a
replacement for the existing GestureBuilder app. To change the
package name, open the manifest file and modify the package attribute
of the manifest element. Next, update imports and other references to
the package name, rebuild the app, and run it in an AVD.</p>
<p>For example, here's how you could do this in Eclipse:</p>
<ol>
<li>Right-click on the package name
(<code>src/com.android.gesture.builder</code>).</li>
<li>Select <strong>Refactor &gt; Rename</strong> and change the name, for example to
<code>com.android.gestureNEW.builder</code>. </li>
<li>Open the manifest file. Inside the <code>&lt;manifest&gt;</code>
tag, change the package name to
<code>com.android.gestureNEW.builder</code>.</li>
<li>Open each of the two Activity files and do Ctrl-Shift-O to add
missing import packages, then save each file.</li>
<li>Run the GestureBuilder application on the emulator.</li>
</ol>
<p>If you get an error message such as "Could not load /sdcard/gestures.
Make sure you have a mounted SD card," be sure that your target AVD has an
SD card. To create an AVD that has an SD card, use the
<a href="{@docRoot}guide/developing/tools/avd.html#options"><code>-c</code>
option</a> in the <code>android create avd</code> command.</p>
<h2 id="signingcalendar">I can't compile my app because the build tools generated an expired debug certificate</h2>
<p>If your development machine uses a locale that has a non-Gregorian calendar, you may encounter problems when first trying to compile and run your application. Specifically, you may find that the Android build tools won't compile your application because the debug key is expired. </p>
<p>The problem occurs because the Keytool utility &mdash; included in the JDK and used by the Android build tools &mdash; fails to properly handle non-Gregorian locales and may create validity dates that are in the past. That is, it may generate a debug key that is already expired, which results in the compile error.</p>
<p>If you encounter this problem, follow these steps to work around it: </p>
<ol>
<li>First, delete the debug keystore/key already generated by the Android build tools. Specifically, delete the <code>debug.keystore</code> file. On Linux/Mac OSX, the file is stored in <code>~/.android</code>. On Windows XP, the file is stored in <code>
C:\Documents and Settings\&lt;user&gt;\.android</code>. On Windows Vista, the file is stored in <code>
C:\Users\&lt;user&gt;\.android</code></li>
<li>Next, you can either
<ul>
<li>Temporarily change your development machine's locale (date and time) to one that uses a Gregorian calendar, for example, United States. Once the locale is changed, use the Android build tools to compile and install your app. The build tools will regenerate a new keystore and debug key with valid dates. Once the new debug key is generated, you can reset your development machine to the original locale. </li>
<li>Alternatively, if you do not want to change your machine's locale settings, you can generate the keystore/key on any machine using the Gregorian calendar, then copy the <code>debug.keystore</code> file from that computer to the proper location on your development machine. </li>
</ul>
</li>
</ol>
<p>This problem has been verified on Windows and may apply to other platforms. </p>
<p>For general information about signing Android applications, see
<a href="{@docRoot}guide/publishing/app-signing.html">Signing Your Applications</a>. </p>
<h2 id="manifestfiles">Unable to view manifest files from within
Eclipse</a></h2>
<p>When you try to open an application's manifest file from within
Eclipse, you might get an error such as this one:</p>
<pre>An error has occurred. See error log for more details.
org.eclipse.wst.sse.ui.StructuredTextEditor.isBlockSelectionModeEnabled()Z</pre>
<p>Try reverting to the 3.0 version of the Eclipse XML Editors and
Tools. If this does not work, remove the 3.1 version of the tool. To do
this in Eclipse 3.4:</p>
<ol>
<li>Select <strong>Help > Software Updates...</strong></li>
<li>Select the <strong>Installed Software</strong> tab.</li>
<li>Select <strong>Eclipse XML Editors and Tools</strong>.</li>
<li>Click <strong>Uninstall</strong>.</li>
<li>Click <strong>Finish</strong>.</li>
</ol>
<p>When you restart Eclipse, you should be able to view the manifest
files. </p>
@@ -0,0 +1,115 @@
page.title=Intents List: Invoking Google Applications on Android Devices
@jd:body
<div class="sidebox-wrapper">
<div class="sidebox">
For more information about intents, see the <a
href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and Intent Filters</a>.
</div>
</div>
<p>The table below lists the intents that your application can send, to invoke Google applications on Android devices in certain ways. For each action/uri pair, the table describes how the receiving Google application handles the intent. </p>
<p>Note that this list is not comprehensive.</p>
<table>
<tr>
<th scope="col">Target Application</th>
<th scope="col">Intent URI</th>
<th scope="col">Intent Action</th>
<th scope="col">Result</th>
</tr>
<tr>
<td rowspan="2">Browser</td>
<td>http://<em>web_address</em><br />
https://<em>web_address</em></td>
<td>VIEW</td>
<td>Open a browser window to the URL specified. </td>
</tr>
<tr>
<td>&quot;&quot; (empty string) <br />
http://<em>web_address</em><br />
https://<em>web_address</em></td>
<td>WEB_SEARCH</td>
<td>Opens the file at the location on the device in the browser. </td>
</tr>
<tr>
<td rowspan="2">Dialer</td>
<td height="103">tel: <em>phone_number</em></td>
<td>CALL</td>
<td><p>Calls the entered phone number. Valid telephone numbers as defined
in <a href="http://tools.ietf.org/html/rfc3966">the IETF RFC 3966</a> are
accepted. Valid examples include the following:</p>
<ul>
<li>tel:2125551212 </li>
<li>tel:
(212) 555 1212</li>
</ul>
<p>The dialer is good at normalizing some kinds of schemes: for example
telephone numbers, so the schema described isn't strictly required
in the {@link android.net.Uri#parse(java.lang.String)
Uri(URI string)} factory. However, if you have not tried a
schema or are unsure whether it can be handled, use the {@link
android.net.Uri#fromParts(java.lang.String, java.lang.String,
java.lang.String) Uri.fromParts(scheme, ssp, fragment)} factory
instead.</p>
<p><strong><em>Note:</em></strong>&nbsp;&nbsp;&nbsp;This requires your
application to request the following permission in your manifest: <code>&lt;uses-permission
id=&quot;android.permission.CALL_PHONE&quot; /&gt;</code></p></td>
</tr>
<tr>
<td><p>tel:<em>phone_number</em><br />
voicemail:</p> </td>
<td>DIAL</td>
<td><p>Dials (but does not actually initiate the call) the number given
(or the stored voicemail on the phone). Telephone number normalization
described for CALL applies to DIAL as well. </p> </td>
</tr>
<tr>
<td>Google Maps</td>
<td>geo:<em>latitude</em>,<em>longitude</em><br />
geo:<em>latitude</em>,<em>longitude</em>?z=<em>zoom</em><br />
geo:0,0?q=<em>my+street+address</em><br />
geo:0,0?q=<em>business+near+city</em><br />
</td>
<td>VIEW</td>
<td>Opens the Maps application to the given location or query. The Geo URI scheme
(not fully supported) is <a href="http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00">currently under
development</a>.<p>
The <em>z</em> field specifies the zoom level. A zoom level of 1 shows the whole Earth, centered at the
given <em>lat</em>,<em>lng</em>. A zoom level of 2 shows a quarter of the Earth, and so on. The highest
zoom level is 23. A larger zoom level will be clamped to 23.
</td>
</tr>
<tr>
<td>Google Streetview</td>
<td>google.streetview:cbll=<em>lat</em>,<em>lng</em>&amp;cbp=1,<em>yaw</em>,,<em>pitch</em>,<em>zoom</em>&amp;mz=<em>mapZoom</em>
</td>
<td>VIEW</td>
<td>Opens the Street View application to the given location. The URI scheme is
based on the syntax used for Street View panorama information in Google Maps URLs.<p>
The cbll field is required. The cbp and mz fields are optional.<p>
<table border:none>
<tr><td><em>lat</em></td><td>latitude</td></tr>
<tr><td><em>lng</em></td><td>longitude</td></tr>
<tr><td><em>yaw</em></td><td>Panorama center-of-view in degrees clockwise from North.<br />
<b>Note:</b> The two commas after the yaw parameter are required. They are present
for backwards-compatibility reasons.</td></tr>
<tr><td><em>pitch</em></td><td>Panorama center-of-view in degrees from
-90 (look straight up) to 90 (look straight down.)</td></tr>
<tr><td><em>zoom</em></td><td>Panorama zoom. 1.0 = normal zoom, 2.0 = zoomed in 2x, 3.0 = zoomed in 4x, and so on.<br />
A zoom of 1.0 is 90 degree horizontal FOV for a nominal landscape mode 4
x 3 aspect ratio display Android phones in portrait mode will adjust the zoom so
that the vertical FOV is approximately the same as the landscape vertical FOV.
This means that the horizontal FOV of an Android phone in portrait mode is much
narrower than in landscape mode. This is done to minimize the fisheye lens
effect that would be present if a 90 degree horizontal FOV was used in portrait
mode.</td></tr>
<tr><td><em>mapZoom</em></td><td>The map zoom of the map location associated with this panorama. This value is passed on to the
Maps activity when the Street View "Go to Maps" menu item is chosen. It corresponds to the <em>z</em> parameter in
the geo: intent.</td></tr>
</table>
</td>
</tr>
</table>
<p></p>
+293
View File
@@ -0,0 +1,293 @@
page.title=Glossary
@jd:body
<p>The list below defines some of the basic terminology of the Android platform. </p>
<dl>
<dt id="apk">.apk file</dt> <dd>Android application package file. Each
Android application is compiled and packaged in a single file that
includes all of the application's code (.dex files), resources, assets,
and manifest file. The application package file can have any name but
<em>must</em> use the <code>.apk</code> extension. For example:
<code>myExampleAppname.apk</code>. For convenience, an application package
file is often referred to as an ".apk".
<p>Related: <a href="#application">Application</a>.</p>
</dd>
<dt id="dex">.dex file </dt>
<dd>Compiled Android application code file.
<p>Android programs are compiled into .dex (Dalvik Executable) files, which
are in turn zipped into a single .apk file on the device. .dex files can
be created by automatically translating compiled applications written in
the Java programming language.</dd>
<dt id="action">Action</dt>
<dd>A description of something that an Intent sender wants done. An action is
a string value assigned to an Intent. Action strings can be defined by Android
or by a third-party developer. For example, android.intent.action.VIEW
for a Web URL, or com.example.rumbler.SHAKE_PHONE for a custom application
to vibrate the phone.
<p>Related: <a href="#intent">Intent</a>.</p>
</dd>
<dt id="activity">Activity</dt>
<dd>A single screen in an application, with supporting Java code, derived
from the {@link android.app.Activity} class. Most commonly, an activity is
visibly represented by a full screen window that can receive and handle UI
events and perform complex tasks, because of the Window it uses to render
its window. Though an Activity is typically full screen, it can also be
floating or transparent.</dd>
<dt id="adb">adb</dt>
<dd>Android Debug Bridge, a command-line debugging application included with the
SDK. It provides tools to browse the device, copy tools on the device, and
forward ports for debugging. If you are developing in Eclipse using the
ADT Plugin, adb is integrated into your development environment. See
<a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a>
for more information. </dd>
<dt id="application">Application</dt>
<dd>From a component perspective, an Android application consists of one
or more activities, services, listeners, and intent receivers. From a
source file perspective, an Android application consists of code,
resources, assets, and a single manifest. During compilation, these files
are packaged in a single file called an application package file (.apk).
<p>Related: <a href="#apk">.apk</a>, <a href="#activity">Activity</a></p></dd>
<dt id="canvas">Canvas</dt>
<dd>A drawing surface that handles compositing of the actual bits against
a Bitmap or Surface object. It has methods for standard computer drawing
of bitmaps, lines, circles, rectangles, text, and so on, and is bound to a
Bitmap or Surface. Canvas is the simplest, easiest way to draw 2D objects
on the screen. However, it does not support hardware acceleration, as
OpenGL ES does. The base class is {@link android.graphics.Canvas}.
<p>Related: <a href="#drawable">Drawable</a>, <a href="#opengles">OpenGL
ES</a>.</p></dd>
<dt id="contentprovider">Content Provider</dt>
<dd>A data-abstraction layer that you can use to safely expose your
application's data to other applications. A content provider is built on
the {@link android.content.ContentProvider} class, which handles content
query strings of a specific format to return data in a specific format.
See <a href="{@docRoot}guide/topics/providers/content-providers.html">
Content Providers</a> topic for more information.
<p>Related: <a href="#uri">URI Usage in Android</a></p></dd>
<dt id="dalvik">Dalvik</dt>
<dd>The Android platform's virtual machine. The Dalvik VM is an
interpreter-only virtual machine that executes files in the Dalvik
Executable (.dex) format, a format that is optimized for efficient storage
and memory-mappable execution. The virtual machine is register-based, and
it can run classes compiled by a Java language compiler that have been
transformed into its native format using the included &quot;dx&quot; tool.
The VM runs on top of Posix-compliant operating systems, which it relies
on for underlying functionality (such as threading and low level memory
management). The Dalvik core class library is intended to provide a
familiar development base for those used to programming with Java Standard
Edition, but it is geared specifically to the needs of a small mobile
device.</dd>
<dt id="ddms">DDMS</dt>
<dd>Dalvik Debug Monitor Service, a GUI debugging application included
with the SDK. It provides screen capture, log dump, and process
examination capabilities. If you are developing in Eclipse using the ADT
Plugin, DDMS is integrated into your development environment. See <a
href="{@docRoot}guide/developing/tools/ddms.html">Dalvik Debug Monitor
Server</a> to learn more about the program.</dd>
<dt id="dialog">Dialog</dt> <dd> A floating window that that acts as a lightweight
form. A dialog can have button controls only and is intended to perform a
simple action (such as button choice) and perhaps return a value. A dialog
is not intended to persist in the history stack, contain complex layout,
or perform complex actions. Android provides a default simple dialog for
you with optional buttons, though you can define your own dialog layout.
The base class for dialogs is {@link android.app.Dialog Dialog}.
<p>Related: <a href="#activity">Activity</a>.</p></dd>
<dt id="drawable">Drawable</dt>
<dd>A compiled visual resource that can be used as a background, title, or
other part of the screen. A drawable is typically loaded into another UI
element, for example as a background image. A drawable is not able to
receive events, but does assign various other properties such as "state"
and scheduling, to enable subclasses such as animation objects or image
libraries. Many drawable objects are loaded from drawable resource files
&mdash; xml or bitmap files that describe the image. Drawable resources
are compiled into subclasses of {@link android.graphics.drawable}. For
more information about drawables and other resources, see <a
href="{@docRoot}guide/topics/resources/resources-i18n.html">Resources</a>.
<p>Related: <a href="#resources">Resources</a>, <a href="#canvas">Canvas
</a></p></dd>
<dt id="intent">Intent</dt>
<dd>An message object that you can use to launch or communicate with other
applications/activities asynchronously. An Intent object is an instance of
{@link android.content.Intent}. It includes several criteria fields that you can
supply, to determine what application/activity receives the Intent and
what the receiver does when handling the Intent. Available criteria include
include the desired action, a category, a data string, the MIME type of
the data, a handling class, and others. An application sends
an Intent to the Android system, rather than sending it directly to
another application/activity. The application can send the Intent to a
single target application or it can send it as a broadcast, which can in
turn be handled by multiple applications sequentially. The Android system
is responsible for resolving the best-available receiver for each Intent,
based on the criteria supplied in the Intent and the Intent Filters
defined by other applications. For more information, see <a
href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and
Intent Filters</a>.
<p>Related: <a href="#intentfilter">Intent Filter</a>, <a
href="#broadcastreceiver">Broadcast Receiver</a>.</p></dd>
<dt id="intentfilter">Intent Filter</dt>
<dd>A filter object that an application declares in its manifest file, to
tell the system what types of Intents each of its components is willing to
accept and with what criteria. Through an intent filter, an application
can express interest in specific data types, Intent actions, URI formats,
and so on. When resolving an Intent, the system evaluates all of the
available intent filters in all applications and passes the Intent to the
application/activity that best matches the Intent and criteria. For more
information, see <a
href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and
Intent Filters</a>.
<p>Related: <a href="#intent">Intent</a>, <a
href="#broadcastreceiver">Broadcast Receiver</a>.</p></dd>
<dt id="broadcastreceiver">Broadcast Receiver </dt>
<dd>An application class that listens for Intents that are broadcast,
rather than being sent to a single target application/activity. The system
delivers a broadcast Intent to all interested broadcast receivers, which
handle the Intent sequentially.
<p>Related: <a href="#intent">Intent</a>, <a href="#intentfilter">Intent
Filter</a>.</p> </dd>
<dt id="layoutresource">Layout Resource</dt>
<dd>An XML file that describes the layout of an Activity screen.
<p>Related: <a href="#resources">Resources</a></p></dd>
<dt id="manifest">Manifest File</dt>
<dd>An XML file that each application must define, to describe the
application's package name, version, components (activities, intent
filters, services), imported libraries, and describes the various
activities, and so on. See <a
href="{@docRoot}guide/topics/manifest/manifest-intro.html">The
AndroidManifest.xml File</a> for complete information.</dd>
<dt id="ninepatch">Nine-patch / 9-patch / Ninepatch image</dt>
<dd>A resizeable bitmap resource that can be used for backgrounds or other
images on the device. See <a
href="{@docRoot}guide/topics/resources/available-resources.html#ninepatch">
Nine-Patch Stretchable Image</a> for more information.
<p>Related: <a href="#resources">Resources</a>.</p></dd>
<dt id="opengles">OpenGL ES</dt>
<dd> Android provides OpenGL ES libraries that you can use for fast,
complex 3D images. It is harder to use than a Canvas object, but
better for 3D objects. The {@link android.opengl} and
{@link javax.microedition.khronos.opengles} packages expose
OpenGL ES functionality.
<p>Related: <a href="#canvas">Canvas</a>, <a href="#surface">Surface</a></p></dd>
<dt id="resources">Resources</dt>
<dd>Nonprogrammatic application components that are external to the
compiled application code, but which can be loaded from application code
using a well-known reference format. Android supports a variety of
resource types, but a typical application's resources would consist of UI
strings, UI layout components, graphics or other media files, and so on.
An application uses resources to efficiently support localization and
varied device profiles and states. For example, an application would
include a separate set of resources for each supported local or device
type, and it could include layout resources that are specific to the
current screen orientation (landscape or portrait). For more information
about resources, see <a
href="{@docRoot}guide/topics/resources/index.html"> Resources and
Assets</a>. The resources of an application are always stored in the
<code>res/*</code> subfolders of the project. </dd>
<dt id="service">Service</dt>
<dd>An object of class {@link android.app.Service} that runs in the
background (without any UI presence) to perform various persistent
actions, such as playing music or monitoring network activity.
<p>Related: <a href="#activity">Activity</a></p></dd>
<dt id="surface">Surface</dt>
<dd>An object of type {@link android.view.Surface} representing a block of
memory that gets composited to the screen. A Surface holds a Canvas object
for drawing, and provides various helper methods to draw layers and resize
the surface. You should not use this class directly; use
{@link android.view.SurfaceView} instead.
<p>Related: <a href="#canvas">Canvas</a></p></dd>
<dt id="surfaceview">SurfaceView</dt>
<dd>A View object that wraps a Surface for drawing, and exposes methods to
specify its size and format dynamically. A SurfaceView provides a way to
draw independently of the UI thread for resource-intensive operations
(such as games or camera previews), but it uses extra memory as a result.
SurfaceView supports both Canvas and OpenGL ES graphics. The base class is
{@link android.view.SurfaceView}.
<p>Related: <a href="#canvas">Surface</a></p></dd>
<dt id="theme">Theme</dt>
<dd>A set of properties (text size, background color, and so on) bundled
together to define various default display settings. Android provides a
few standard themes, listed in {@link android.R.style} (starting with
&quot;Theme_&quot;). </dd>
<dt id="uri">URIs in Android</dt>
<dd>Android uses URI strings as the basis for requesting data in a content
provider (such as to retrieve a list of contacts) and for requesting
actions in an Intent (such as opening a Web page in a browser). The URI
scheme and format is specialized according to the type of use, and an
application can handle specific URI schemes and strings in any way it
wants. Some URI schemes are reserved by system components. For example,
requests for data from a content provider must use the
<code>content://</code>. In an Intent, a URI using an <code>http://</code>
scheme will be handled by the browser. </dd>
<dt id="view">View</dt>
<dd>An object that draws to a rectangular area on the screen and handles
click, keystroke, and other interaction events. A View is a base class for
most layout components of an Activity or Dialog screen (text boxes,
windows, and so on). It receives calls from its parent object (see
viewgroup, below)to draw itself, and informs its parent object about where
and how big it would like to be (which may or may not be respected by the
parent). For more information, see {@link android.view.View}.
<p>Related: <a href="#viewgroup">Viewgroup</a>, <a href="#widget">Widget
</a></p></dd>
<dt id="viewgroup">Viewgroup</dt>
<dd> A container object that groups a set of child Views. The viewgroup is
responsible for deciding where child views are positioned and how large
they can be, as well as for calling each to draw itself when appropriate.
Some viewgroups are invisible and are for layout only, while others have
an intrinsic UI (for instance, a scrolling list box). Viewgroups are all
in the {@link android.widget widget} package, but extend
{@link android.view.ViewGroup ViewGroup}.
<p>Related: <a href="#view">View</a></p></dd>
<dt id="widget">Widget</dt>
<dd>One of a set of fully implemented View subclasses that render form
elements and other UI components, such as a text box or popup menu.
Because a widget is fully implemented, it handles measuring and drawing
itself and responding to screen events. Widgets are all in the
{@link android.widget} package. </dd>
<!--
<dt id="panel">Panel</dt>
<dd> A panel is a concept not backed by a specific class. It is a View of
some sort that is tied in closely to a parent window, but can handle
clicks and perform simple functions related to its parent. A panel floats
in front of its parent, and is positioned relative to it. A common example
of a panel (implemented by Android) is the options menu available to every
screen. At present, there are no specific classes or methods for creating
a panel &mdash; it's more of a general idea. </dd>
-->
<dt id="panel">Window</dt>
<dd>In an Android application, an object derived from the abstract class
{@link android.view.Window} that specifies the elements of a generic
window, such as the look and feel (title bar text, location and content of
menus, and so on). Dialog and Activity use an implementation of this class
to render a window. You do not need to implement this class or use windows
in your application. </dd>
</dl>
+13
View File
@@ -0,0 +1,13 @@
page.title=Appendix
@jd:body
<dl>
<dt><a href="media-formats.html">Supported Android Media Formats</a></dt>
<dd>A list of media codecs included in the Android platform.</dd>
<dt><a href="g-app-intents.html">Intents List: Invoking Google Applications on Android Devices</a></dt>
<dd>Intents you can send to invoke Google applications on Android devices.</dd>
<dt><a href="faq/index.html">FAQs, Tips, and How-to</a></dt>
<dd>How to get things done in Android.</dd>
<dt><a href="glossary.html">Glossary</a></dt>
<dd>Glossary of Android terminology.</dd>
</dl>
@@ -0,0 +1,201 @@
page.title=App Install Location
@jd:body
<div id="qv-wrapper">
<div id="qv">
<h2>Quickview</h2>
<ul>
<li>You can allow your application to install on the device's external storage.</li>
<li>Some types of applications should <strong>not</strong> allow installation on the external
storage.</li>
<li>Installing on the external storage is ideal for large applications that are not tightly
integrated with the system (most commonly, games).</li>
</ul>
<h2>In this document</h2>
<ol>
<li><a href="#Compatiblity">Backward Compatibility</a></li>
<li><a href="#ShouldNot">Applications That Should NOT Install on External Storage</a></li>
<li><a href="#Should">Applications That Should Install on External Storage</a></li>
</ol>
<h2>See also</h2>
<ol>
<li><code><a href="{@docRoot}guide/topics/manifest/manifest-element.html">
&lt;manifest&gt;</a></code></li>
</ol>
</div>
</div>
<p>Beginning with API Level 8, you can allow your application to be installed on the
external storage (for example, the device's SD card). This is an optional feature you can declare
for your application with the <a
href="{@docRoot}guide/topics/manifest/manifest-element.html#install">{@code
android:installLocation}</a> manifest attribute. If you do
<em>not</em> declare this attribute, your application will be installed on the internal storage
only and it cannot be moved to the external storage.</p>
<p>To allow the system to install your application on the external storage, modify your
manifest file to include the <a
href="{@docRoot}guide/topics/manifest/manifest-element.html#install">{@code
android:installLocation}</a> attribute in the <code><a
href="{@docRoot}guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></code> element,
with a value of either "{@code preferExternal}" or "{@code auto}". For example:</p>
<pre>
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
... &gt;
</pre>
<p>If you declare "{@code preferExternal}", you request that your application be installed on the
external storage, but the system does not guarantee that your application will be installed on
the external storage. If the external storage is full, the system will install it on the internal
storage. The user can also move your application between the two locations.</p>
<p>If you declare "{@code auto}", you indicate that your application may be installed on the
external storage, but you don't have a preference of install location. The system will
decide where to install your application based on several factors. The user can also move your
application between the two locations.</p>
<p>When your application is installed on the external storage:</p>
<ul>
<li>There is no effect on the application performance so long
as the external storage is mounted on the device.</li>
<li>The {@code .apk} file is saved on the external storage, but all private user data,
databases, optimized {@code .dex} files, and extracted native code are saved on the
internal device memory.</li>
<li>The unique container in which your application is stored is encrypted with a randomly
generated key that can be decrypted only by the device that originally installed it. Thus, an
application installed on an SD card works for only one device.</li>
<li>The user can move your application to the internal storage through the system settings.</li>
</ul>
<p class="warning"><strong>Warning:</strong> When the user enables USB mass storage to share files
with a computer or unmounts the SD card via the system settings, the external storage is unmounted
from the device and all applications running on the external storage are immediately killed.</p>
<h2 id="Compatiblity">Backward Compatibility</h2>
<p>The ability for your application to install on the external storage is a feature available only
on devices running API Level 8 (Android 2.2) or greater. Existing applications that were built prior
to API Level 8 will always install on the internal storage and cannot be moved to the external
storage (even on devices with API Level 8). However, if your application is designed to support an
API Level <em>lower than</em> 8, you can choose to support this feature for devices with API Level 8
or greater and still be compatible with devices using an API Level lower than 8.</p>
<p>To allow installation on external storage and remain compatible with versions lower than API
Level 8:</p>
<ol>
<li>Include the {@code android:installLocation} attribute with a value of "{@code auto}" or
"{@code preferExternal}" in the <code><a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;manifest&gt;</a></code>
element.</li>
<li>Leave your {@code android:minSdkVersion} attribute as is (something <em>less
than</em> "8") and be certain that your application code uses only APIs compatible with that
level.</li>
<li>In order to compile your application, change your build target to API Level 8. This is
necessary because older Android libraries don't understand the {@code android:installLocation}
attribute and will not compile your application when it's present.</li>
</ol>
<p>When your application is installed on a device with an API Level lower than 8, the {@code
android:installLocation} attribute is ignored and the application is installed on the internal
storage.</p>
<p class="caution"><strong>Caution:</strong> Although XML markup such as this will be ignored by
older platforms, you must be careful not to use programming APIs introduced in API Level 8
while your {@code minSdkVersion} is less than "8", unless you perform the work necessary to
provide backward compatibility in your code. For information about building
backward compatibility in your application code, see the <a
href="{@docRoot}resources/articles/backward-compatibility.html">Backward Compatibility</a>
article.</p>
<h2 id="ShouldNot">Applications That Should NOT Install on External Storage</h2>
<p>When the user enables USB mass storage to share files with their computer (or otherwise
unmounts or removes the external storage), any application
installed on the external storage and currently running is killed. The system effectively becomes
unaware of the application until mass storage is disabled and the external storage is
remounted on the device. Besides killing the application and making it unavailable to the user,
this can break some types of applications in a more serious way. In order for your application to
consistently behave as expected, you <strong>should not</strong> allow your application to be
installed on the external storage if it uses any of the following features, due to the cited
consequences when the external storage is unmounted:</p>
<dl>
<dt>Services</dt>
<dd>Your running {@link android.app.Service} will be killed and will not be restarted when
external storage is remounted. You can, however, register for the {@link
android.content.Intent#ACTION_EXTERNAL_APPLICATIONS_AVAILABLE} broadcast Intent, which will notify
your application when applications installed on external storage have become available to the
system again. At which time, you can restart your Service.</dd>
<dt>Alarm Services</dt>
<dd>Your alarms registered with {@link android.app.AlarmManager} will be cancelled. You must
manually re-register any alarms when external storage is remounted.</dd>
<dt>Input Method Engines</dt>
<dd>Your <a href="{@docRoot}resources/articles/on-screen-inputs.html">IME</a> will be
replaced by the default IME. When external storage is remounted, the user can open system settings
to enable your IME again.</dd>
<dt>Live Wallpapers</dt>
<dd>Your running <a href="{@docRoot}resources/articles/live-wallpapers.html">Live Wallpaper</a>
will be replaced by the default Live Wallpaper. When external storage is remounted, the user can
select your Live Wallpaper again.</dd>
<dt>Live Folders</dt>
<dd>Your <a href="{@docRoot}resources/articles/live-folders.html">Live Folder</a> will be
removed from the home screen. When external storage is remounted, the user can add your Live Folder
to the home screen again.</dd>
<dt>App Widgets</dt>
<dd>Your <a href="{@docRoot}guide/topics/appwidgets/index.html">App Widget</a> will be removed
from the home screen. When external storage is remounted, your App Widget will <em>not</em> be
available for the user to select until the system resets the home application (usually not until a
system reboot).</dd>
<dt>Account Managers</dt>
<dd>Your accounts created with {@link android.accounts.AccountManager} will disappear until
external storage is remounted.</dd>
<dt>Sync Adapters</dt>
<dd>Your {@link android.content.AbstractThreadedSyncAdapter} and all its sync functionality will
not work until external storage is remounted.</dd>
<dt>Device Administrators</dt>
<dd>Your {@link android.app.admin.DeviceAdminReceiver} and all its admin capabilities will
be disabled, which can have unforeseeable consequences for the device functionality, which may
persist after external storage is remounted.</dd>
<dt>Broadcast Receivers listening for "boot completed"</dt>
<dd>The system delivers the {@link android.content.Intent#ACTION_BOOT_COMPLETED} broadcast
before the external storage is mounted to the device. If your application is installed on the
external storage, it can never receive this broadcast.</dd>
</dl>
<p>If your application uses any of the features listed above, you <strong>should not</strong> allow
your application to install on external storage. By default, the system <em>will not</em> allow your
application to install on the external storage, so you don't need to worry about your existing
applications. However, if you're certain that your application should never be installed on the
external storage, then you should make this clear by declaring <a
href="{@docRoot}guide/topics/manifest/manifest-element.html#install">{@code
android:installLocation}</a> with a value of "{@code internalOnly}". Though this does not
change the default behavior, it explicitly states that your application should only be installed
on the internal storage and serves as a reminder to you and other developers that this decision has
been made.</p>
<h2 id="Should">Applications That Should Install on External Storage</h2>
<p>In simple terms, anything that does not use the features listed in the previous section
are safe when installed on external storage. Large games are more commonly the types of
applications that should allow installation on external storage, because games don't typically
provide additional services when innactive. When external storage becomes unavailable and a game
process is killed, there should be no visible effect when the storage becomes available again and
the user restarts the game (assuming that the game properly saved its state during the normal
<a href="{@docRoot}guide/topics/fundamentals.html#lcycles">Activity lifecycle</a>).</p>
<p>If your application requires several megabytes for the APK file, you should
carefully consider whether to enable the application to install on the external storage so that
users can preserve space on their internal storage.</p>
@@ -0,0 +1,353 @@
page.title=Market Filters
@jd:body
<div id="qv-wrapper">
<div id="qv">
<h2>Quickview</h2>
<ul> <li>Android Market applies filters to that let you control whether your app is shown to a
user who is browing or searching for apps.</li>
<li>Filtering is determined by elements in an app's manifest file,
aspects of the device being used, and other factors.</li> </ul>
<h2>In this document</h2>
<ol> <li><a href="#how-filters-work">How Filters Work in Android Market</a></li>
<li><a href="#manifest-filters">Filtering based on Manifest File Elements</a></li>
<li><a href="#other-filters">Other Filters</a></li>
</ol>
<h2>See also</h2>
<ol>
<li><a
href="{@docRoot}guide/practices/compatibility.html">Compatibility</a></li>
<li style="margin-top:2px;"><code><a
href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code></li>
<li><code><a
href="{@docRoot}guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></code></li>
<li><code><a
href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></code></li>
<li><code><a
href="{@docRoot}guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></code></li>
<li><code><a
href="{@docRoot}guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></code></li>
<li><code><a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</code></a></li>
</ol>
<div id="qv-extra"> <img id="rule" src="{@docRoot}assets/images/grad-rule-qv.png">
<div id="qv-sub-rule"> <img src="{@docRoot}assets/images/icon_market.jpg"
style="float:left;margin:0;padding:0;"> <p style="color:#669999;">Interested in
publishing your app on Android Market?</p> <a id="publish-link"
href="http://market.android.com/publish">Go to Android Market &raquo;</a> </div>
</div>
</div> </div>
<p>When a user searches or browses in Android Market, the results are filtered, and
some applications might not be visible. For example, if an application requires a
trackball (as specified in the manifest file), then Android Market will not show
the app on any device that does not have a trackball.</p> <p>The manifest file and
the device's hardware and features are only part of how applications are filtered
&#8212; filtering also depends on the country and carrier, the presence or absence
of a SIM card, and other factors. </p>
<p>Changes to the Android Market filters are independent of changes
to the Android platform itself. This document will be updated periodically to reflect
any changes that occur. </p>
<h2 id="how-filters-work">How Filters Work in Android Market</h2>
<p>Android Market uses the filter restrictions described below to determine
whether to show your application to a user who is browsing or searching for
applications on a given device. When determining whether to display your app,
Market checks the device's hardware and software capabilities, as well as it's
carrier, location, and other characteristics. It then compares those against the
restrictions and dependencies expressed by the application itself, in its
manifest, <code>.apk</code>, and publishing details. If the application is
compatible with the device according to the filter rules, Market displays the
application to the user. Otherwise, Market hides your application from search
results and category browsing. </p>
<p> You can use the filters described below to control whether Market shows or
hides your application to users. You can request any combination of the
available filters for your app &#8212; for example, you could set a
<code>minSdkVersion</code> requirement of <code>"4"</code> and set
<code>smallScreens="false"</code> in the app, then when uploading the app to
Market you could target European countries (carriers) only. Android Market's
filters would prevent the application from being visible on any device that did
not match all three of these requirements. </p>
<p>A filtered app is not visible within Market, even if a user specifically requests
the app by clicking a deep link that points directly to the app's ID within Market.
All filtering restrictions are associated with an application's version and can
change between versions. For example:</p>
<ul>
<li>If you publish a new version of your app with stricter restrictions, the app
will not be visible to users for whom it is filtered, even if those users were
able see the previous version.</li>
<li>If a user has installed your application and you publish an upgrade that
makes the app invisible to the user, the user will not see that an upgrade is
available. </li>
</ul>
<h2 id="manifest-filters">Filtering based on Manifest Elements</h2>
<p>Most Market filters are triggered by elements within an application's
manifest file, <a
href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a>,
although not everything in the manifest file can trigger filtering. The
table below lists the manifest elements that you can use to trigger Android
Market filtering, and explains how the filtering works.</p>
<p class="table-caption"><strong>Table 1.</strong> Manifest elements that
trigger filtering on Market.</p>
<table>
<tr>
<th>Manifest Element</th>
<th>Filter Name</th>
<th>How It Works</th>
</tr>
<tr>
<td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code>
<!-- ##api level 4## --></td>
<td valign="top">Screen Size</td>
<td valign="top">
<p>An application indicates the screen sizes that it is capable of supporting by
setting attributes of the <code>&lt;supports-screens&gt;</code> element. When
the application is published, Market uses those attributes to determine whether
to show the application to users, based on the screen sizes of their
devices. </p>
<p>As a general rule, Market assumes that the platform on the device can adapt
smaller layouts to larger screens, but cannot adapt larger layouts to smaller
screens. Thus, if an application declares support for "normal" screen size only,
Market makes the application available to both normal- and large-screen devices,
but filters the application so that it is not available to small-screen
devices.</p>
<p>If an application does not declare attributes for
<code>&lt;supports-screens&gt;</code>, Market uses the default values for those
attributes, which vary by API Level. Specifically: </p>
<ul>
<li><p>In API level 3, the <code>&lt;supports-screens&gt;</code> element itself
is undefined and no attributes are available. In this case, Market assumes that
the application is designed for normal-size screens and shows the application to
devices that have normal or large screens. </p>
<p>This behavior is especially significant for applications that set their
<code><a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">android:
minSdkVersion</a></code> to 3 or lower, since Market will filter them from
small-screen devices by default. Such applications can enable support for
small-screen devices by adding a <code>android:targetSdkVersion="4"</code>
attribute to the <code>&lt;uses-sdk&gt;</code> element in their manifest
files. For more information, see <a
href="{@docRoot}guide/practices/screens_support.html#strategies">Strategies for
Legacy Applications</a>.</p></li>
<li>In API Level 4, the defaults for all of the attributes is
<code>"true"</code>. If an application does not declare a
<code>&lt;supports-screens&gt;</code> element, Market assumes that the
application is designed for all screen sizes and does not filter it from any
devices. If the application does not declare one of the attributes, Market uses
the default value of <code>"true"</code> and does not filter the app for devices
of corresponding screen size.</li>
</ul>
<p><strong>Example 1</strong><br />
The manifest declares <code>&lt;uses-sdk android:minSdkVersion="3"&gt;</code>
and does not does not include a <code>&lt;supports-screens&gt;</code> element.
<strong>Result</strong>: Android Market will not show the app to a user of a
small-screen device, but will show it to users of normal and large-screen
devices, users, unless other filters apply. </p>
<p><strong>Example 2<br />
</strong>The manifest declares <code>&lt;uses-sdk android:minSdkVersion="3"
android:targetSdkVersion="4"&gt;</code> and does not include a
<code>&lt;supports-screens&gt;</code> element.
<strong>Result</strong>: Android Market will show the app to users on all
devices, unless other filters apply. </p>
<p><strong>Example 3<br />
</strong>The manifest declares <code>&lt;uses-sdk android:minSdkVersion="4"&gt;</code>
and does not include a <code>&lt;supports-screens&gt;</code> element.
<strong>Result</strong>: Android Market will show the app to all users,
unless other filters apply. </p>
<p>For more information on how to declare support for screen sizes in your
application, see <code><a
href="{@docRoot}guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></code>
and <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
Screens</a>.</p>
</td>
</tr>
<tr>
<td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></code>
<!-- ##api level 3## --></td>
<td valign="top">Device
Configuration: <br />
keyboard, navigation, touch screen</td>
<td valign="top"><p>An application can
request certain hardware features, and Android Market will show the app only on devices that have the required hardware.</p>
<p><strong>Example 1<br />
</strong>The manifest includes <code>&lt;uses-configuration android:reqFiveWayNav=&quot;true&quot; /&gt;</code>, and a user is searching for apps on a device that does not have a five-way navigational control. <strong>Result</strong>: Android Market will not show the app to the user. </p>
<p><strong>Example 2<br />
</strong>The manifest does not include a <code>&lt;uses-configuration&gt;</code> element. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply.</p>
<p>For more details, see <a
href="{@docRoot}guide/topics/manifest/uses-configuration-element.html"><code>&lt;uses-configuration&gt;</code></a>.</p></td>
</tr>
<tr>
<td rowspan="2" valign="top" style="white-space:nowrap;"><code><a
href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a>
</code>
<!-- ##api level 4## --></td>
<td valign="top">Device Features<br />
(<code>name</code>)</td>
<td valign="top"><p>An application can require certain device features to be
present on the device. This functionality was introduced in Android 2.0 (API
Level 5).</p>
<p><strong>Example 1<br />
</strong>The manifest includes <code>&lt;uses-feature
android:name=&quot;android.hardware.sensor.light&quot; /&gt;</code>, and a user
is searching for apps on a device that does not have a light sensor.
<strong>Result</strong>: Android Market will not show the app to the user. </p>
<p><strong>Example 2<br />
</strong>The manifest does not include a <code>&lt;uses-feature&gt;</code>
element. <strong>Result</strong>: Android Market will show the app to all users,
unless other filters apply.</p>
<p>For complete information, see <code><a
href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a>
</code>.</p>
<p><em>Filtering based on implied features:</em> In some cases, Android
Market interprets permissions requested through
<code>&lt;uses-permission&gt;</code> elements as feature requirements equivalent
to those declared in <code>&lt;uses-feature&gt;</code> elements. See <a
href="#uses-permission-filtering"><code>&lt;uses-permission&gt;</code></a>,
below.</p>
</td>
</tr>
<tr>
<td valign="top">OpenGL-ES
Version<br />
(<code>openGlEsVersion</code>)</td>
<td valign="top"><p>An application can require that the device support a specific
OpenGL-ES version using the <code>&lt;uses-feature
android:openGlEsVersion=&quot;int&quot;&gt;</code> attribute.</p>
<p><strong>Example 1<br />
</strong>An app
requests multiple OpenGL-ES versions by specifying <code>openGlEsVersion</code> multiple times in the
manifest. <strong>Result</strong>: Market assumes that the app requires the highest of the indicated versions.</p>
<p><strong>Example 2<br />
</strong>An app
requests OpenGL-ES version 1.1, and a user is searching for apps on a device that supports OpenGL-ES version 2.0. <strong>Result</strong>: Android Market will show the app to the user, unless other filters apply. If a
device reports that it supports OpenGL-ES version <em>X</em>, Market assumes that it
also supports any version earlier than <em>X</em>.
</p>
<p><strong>Example 3<br />
</strong>A user is searching for apps on a device that does not
report an OpenGL-ES version (for example, a device running Android 1.5 or earlier). <strong>Result</strong>: Android Market assumes that the device
supports only OpenGL-ES 1.0. Market will only show the user apps that do not specify <code>openGlEsVersion</code>, or apps that do not specify an OpenGL-ES version higher than 1.0. </p>
<p><strong>Example 4<br />
</strong>The manifest does not specify <code>openGlEsVersion</code>. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply. </p>
<p>For more details, see <a
href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><code>&lt;uses-feature&gt;</code></a>.</p></td>
</tr>
<tr>
<td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></code></td>
<td valign="top">Software Libraries</td>
<td valign="top"><p>An application can require specific
shared libraries to be present on the device. </p>
<p><strong>Example 1<br />
</strong>An app requires the <code>com.google.android.maps</code> library, and a user is searching for apps on a device that does not have the <code>com.google.android.maps</code> library. <strong>Result</strong>: Android Market will not show the app to the user. </p>
<p><strong>Example 2</strong><br />
The manifest does not include a <code>&lt;uses-library&gt;</code> element. <strong>Result</strong>: Android Market will show the app to all users, unless other filters apply.</p>
<p>For more details, see <a
href="{@docRoot}guide/topics/manifest/uses-library-element.html"><code>&lt;uses-library&gt;</code></a>.</p></td>
</tr>
<tr id="uses-permission-filtering">
<td valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></code></td>
<td valign="top">&nbsp;</td>
<td valign="top">Strictly, Android Market does not filter based on
<code>&lt;uses-permission&gt;</code> elements. However, it does read the
elements to determine whether the application has hardware feature requirements
that may not have been properly declared in <code>&lt;uses-feature&gt;</code>
elements. For example, if an application requests the <code>CAMERA</code>
permission but does not declare a <code>&lt;uses-feature&gt;</code> element for
<code>android.hardware.camera</code>, Android Market considers that the
application requires a camera and should not be shown to users whose devices do
not offer a camera.</p>
<p>In general, if an application requests hardware-related permissions,
Android Market assumes that the application requires the underlying hardware
features, even though there might be no corresponding to
<code>&lt;uses-feature&gt;</code> declarations. Android Market then sets up
filtering based on the features implied by the <code>&lt;uses-feature&gt;</code>
declarations.</p>
<p>For a list of permissions that imply hardware features, see
the documentation for the <a
href="{@docRoot}guide/topics/manifest/uses-feature-element.html#permissions-features"><code>&lt;uses-feature&gt;</code></a>
element.</p>
</td>
</tr>
<tr>
<td rowspan="2" valign="top" style="white-space:nowrap;"><code><a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a></code></td>
<td valign="top">Minimum Framework Version (<code>minSdkVersion</code>)</td>
<td valign="top"><p>An application can require a minimum API level. </p>
<p><strong>Example 1</strong><br />
The manifest includes <code>&lt;uses-sdk
android:minSdkVersion=&quot;3&quot;&gt;</code>, and the app uses APIs that were introduced in API Level 3. A user is searching for apps on a device that has API Level 2. <strong>Result</strong>: Android Market will not show the app to the user. </p>
<p><strong>Example 2</strong><br />
The manifest does not include <code>minSdkVersion</code>, and the app uses APIs that were introduced in API Level 3. A user is searching for apps on a device that has API Level 2. <strong>Result</strong>: Android Market assumes that <code>minSdkVersion</code> is &quot;1&quot; and that the app is compatible with all versions of Android. Market shows the app to the user and allows the user to download the app. The app crashes at runtime. </p>
<p>Because you want to avoid this second scenario, we recommend that you always declare a <code>minSdkVersion</code>. For details, see <a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min"><code>android:minSdkVersion</code></a>.</p></td>
</tr>
<tr>
<td valign="top">Maximum Framework Version (<code>maxSdkVersion</code>)</td>
<td valign="top"><p><em>Deprecated.</em> Android
2.1 and later do not check or enforce the <code>maxSdkVersion</code> attribute, and
the SDK will not compile if <code>maxSdkVersion</code> is set in an app's manifest. For devices already
compiled with <code>maxSdkVersion</code>, Market will respect it and use it for
filtering.</p>
<p> Declaring <code>maxSdkVersion</code> is <em>not</em> recommended. For details, see <a
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#max"><code>android:maxSdkVersion</code></a>.</p></td>
</tr>
</table>
<h2 id="other-filters">Other Filters</h2>
<p>Android Market uses other application characteristics to determine whether to show or hide an application for a particular user on a given device, as described in the table below. </p>
<p class="table-caption"><strong>Table 2.</strong> Application and publishing characteristics that affect filtering on Market.</p>
<table> <tr>
<th>Filter Name</th> <th>How It Works</th> </tr>
<tr>
<td valign="top">Publishing Status</td> <td valign="top"><p>Only published applications will appear in
searches and browsing within Android Market.</p> <p>Even if an app is unpublished, it can
be installed if users can see it in their Downloads area among their purchased,
installed, or recently uninstalled apps.</p> <p>If an application has been
suspended, users will not be able to reinstall or update it, even if it appears in their Downloads.</p> </td></tr>
<tr>
<td valign="top">Priced
Status</td> <td valign="top"><p>Not all users can see paid apps. To show paid apps, a device
must have a SIM card and be running Android 1.1 or later, and it must be in a
country (as determined by SIM carrier) in which paid apps are available.</p></td>
</tr> <tr>
<td valign="top">Country / Carrier Targeting</td> <td valign="top"> <p>When you upload your app to
the Android Market, you can select specific countries to target. The app will only
be visible to the countries (carriers) that you select, as follows:</p>
<ul><li><p>A device's country is determined based on the carrier, if a carrier is
available. If no carrier can be determined, the Market application tries to
determine the country based on IP.</p></li> <li><p>Carrier is determined based on
the device's SIM (for GSM devices), not the current roaming carrier.</p></li></ul>
</td> </tr> <tr>
<td valign="top">Native Platform</td> <td valign="top"><p>An application that includes native
libraries that target a specific platform (ARM EABI v7, for example) will only be
visible on devices that support that platform. For details about the NDK and using
native libraries, see <a href="{@docRoot}sdk/ndk/index.html#overview">What is the
Android NDK?</a></p> </tr> <tr>
<td valign="top">Forward-Locked Applications</td> <td valign="top"><p>To
forward lock an application, set copy protection to "On" when you upload the
application to Market. Market will not show copy-protected applications on
developer devices or unreleased devices.</p></td> </tr> </table>
@@ -0,0 +1,158 @@
page.title=Android Supported Media Formats
@jd:body
<p>The <a href="#core">Core Media Formats</a> table below describes the media format support built into the Android platform. Note that any given mobile device may provide support for additional formats or file types not listed in the table. </p>
<p>As an application developer, you are free to make use of any media codec that is available on any Android-powered device, including those provided by the Android platform and those that are device-specific.</p>
<h2 id="core">Core Media Formats</h2>
<table>
<tbody>
<tr>
<th>Type</th>
<th>Format</th>
<th>Encoder</th>
<th>Decoder</th>
<th>Details</th>
<th>File Type(s) Supported</th>
</tr>
<tr>
<td rowspan="9">Audio</td>
<td>AAC LC/LTP</td>
<td style="text-align: center;">X</td>
<td style="text-align: center;">X</td>
<td rowspan="3">Mono/Stereo content in any combination of standard bit rates up to 160 kbps and sampling rates from 8 to 48kHz</td>
<td rowspan="3">3GPP (.3gp) and MPEG-4 (.mp4, .m4a). No support for raw AAC (.aac)</td>
</tr>
<tr>
<td>HE-AACv1 (AAC+)</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
</tr>
<tr>
<td>HE-AACv2 (enhanced AAC+)</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
</tr>
<tr>
<td>AMR-NB</td>
<td style="text-align: center;">X</td>
<td style="text-align: center;">X</td>
<td>4.75 to 12.2 kbps sampled @ 8kHz</td>
<td>3GPP (.3gp)
</td>
</tr>
<tr>
<td>AMR-WB</td>
<td style="text-align: center;">X</td>
<td style="text-align: center;">X</td>
<td>9 rates from 6.60 kbit/s to 23.85 kbit/s sampled @ 16kHz</td>
<td>3GPP (.3gp)</td>
</tr>
<tr>
<td>MP3</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
<td>Mono/Stereo 8-320Kbps constant (CBR) or variable bit-rate (VBR)
</td>
<td>MP3 (.mp3)</td>
</tr>
<tr>
<td>MIDI</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
<td>MIDI Type 0 and 1. DLS Version 1 and 2. XMF and Mobile XMF. Support for ringtone formats RTTTL/RTX, OTA, and iMelody </td>
<td>Type 0 and 1 (.mid, .xmf, .mxmf). Also RTTTL/RTX (.rtttl, .rtx), OTA (.ota), and iMelody (.imy)</td>
</tr>
<tr>
<td>Ogg Vorbis</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
<td>&nbsp;</td>
<td>Ogg (.ogg)</td>
</tr>
<tr>
<td>PCM/WAVE</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
<td>8- and 16-bit linear PCM (rates up to limit of hardware)</td>
<td>WAVE (.wav)</td>
</tr>
<tr>
<td rowspan="4">Image</td>
<td>JPEG</td>
<td style="text-align: center;">X</td>
<td style="text-align: center;">X</td>
<td>Base+progressive</td>
<td>JPEG (.jpg)</td>
</tr>
<tr>
<td>GIF</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
<td>&nbsp;</td>
<td>GIF (.gif)</td>
</tr>
<tr>
<td>PNG</td>
<td style="text-align: center;">X</td>
<td style="text-align: center;">X</td>
<td>&nbsp;</td>
<td>PNG (.png)</td>
</tr>
<tr>
<td>BMP</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
<td>&nbsp;</td>
<td>BMP (.bmp)</td>
</tr>
<tr>
<td rowspan="3">Video</td>
<td>H.263</td>
<td style="text-align: center;">X</td>
<td style="text-align: center;">X</td>
<td>&nbsp;</td>
<td>3GPP (.3gp) and MPEG-4 (.mp4)</td>
</tr>
<tr>
<td>H.264 AVC</td>
<td style="text-align: center;"></td>
<td style="text-align: center;">X</td>
<td>&nbsp;</td>
<td>3GPP (.3gp) and MPEG-4 (.mp4)</td>
</tr>
<tr>
<td>MPEG-4 SP</td>
<td>&nbsp;</td>
<td style="text-align: center;">X</td>
<td>&nbsp;</td>
<td>3GPP (.3gp)</td>
</tr>
</tbody></table>