Android

The AndroidManifest.xml File

AndroidManifest.xml is a required file for every application. It sits in the root folder for an application, and describes global values for your package, including the application components (activities, services, etc) that the package exposes and the implementation classes for each component, what kind of data each can handle, and where they can be launched.

An important aspect of this file are the intent filters that it includes. These filters describe where and when that activity can be started. When an activity (or the operating system) wants to perform an action such as open a Web page or open a contact picker screen, it creates an Intent object. This object can hold several descriptors describing what you want to do, what data you want to do it to, the type of data, and other bits of information. Android compares the information in an Intent object with the intent filter exposed by every application and finds the activity most appropriate to handle the data or action specified by the caller. More details on intents is given in the Intent reference page.

Besides declaring your application's Activities, Content Providers, Services, and Intent Receivers, you can also specify permissions and instrumentation (security control and testing) in AndroidManifest.xml. For a reference of the tags and their attributes, please see AndroidManifest.

A simple AndroidManifest.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.my_domain.app.helloactivity">
        
    <application android:label="@string/app_name">
    
        <activity android:name=".HelloActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        
    </application>
    
</manifest>

Some general items to note:

  • Almost every AndroidManifest.xml (as well as many other Android XML files) will include the namespace declaration xmlns:android="http://schemas.android.com/apk/res/android" in its first element. This makes a variety of standard Android attributes available in the file, which will be used to supply most of the data for elements in that file.

  • Most manifests include a single <application> element, which defines all of the application-level components and properties that are available in the package.

  • Any package that will be presented to the user as a top-level application available from the program launcher will need to include at least one Activity component that supports the MAIN action and LAUNCHER category as shown here.

Here is a detailed outline of the structure of an AndroidManifest.xml file, describing all tags that are available.

<manifest>
The root node of the file, describing the complete contents of the package. Under it you can place:
<uses-permission>
Requests a security permission that your package must be granted in order for it to operate correctly. See the Security Model document for more information on permissions. A manifest can contain zero or more of these elements.
<permission>
Declares a security permission that can be used to restrict which applications can access components or features in your (or another) package. See the Security Model document for more information on permissions. A manifest can contain zero or more of these elements.
<instrumentation>
Declares the code of an instrumentation component that is available to test the functionality of this or another package. See Instrumentation for more details. A manifest can contain zero or more of these elements.
<application>
Root element containing declarations of the application-level components contained in the package. This element can also include global and/or default attributes for the application, such as a label, icon, theme, required permission, etc. A manifest can contain zero or one of these elements (more than one application tag is not allowed). Under it you can place zero or more of each of the following component declarations:
<activity>
An Activity is the primary facility for an application to interact with the user. The initial screen the user sees when launching an application is an activity, and most other screens they use will be implemented as separate activities declared with additional activity tags.

Note: Every Activity must have an <activity> tag in the manifest whether it is exposed to the world or intended for use only within its own package. If an Activity has no matching tag in the manifest, you won't be able to launch it.

Optionally, to support late runtime lookup of your activity, you can include one or more <intent-filter> elements to describe the actions the activity supports.

<intent-filter>
Declares a specific set of Intent values that a component supports, in the form of an IntentFilter. In addition to the various kinds of values that can be specified under this element, attributes can be given here to supply a unique label, icon, and other information for the action being described.
<action>
An Intent action that the component supports.
<category>
An Intent category that the component supports.
<data>
An Intent data MIME type, Intent data URI scheme, Intent data URI authority, or Intent data URI path that the component supports.

You can also optionally associate one or more pieces of meta-data with your activity that other clients can retrieve to find additional arbitrary information about it:

<meta-data>
Adds a new piece of meta data to the activity, which clients can retrieve through ComponentInfo.metaData.
<receiver>
An BroadcastReceiver allows an application to be told about changes to data or actions that happen, even if it is not currently running. As with the activity tag, you can optionally include one or more <intent-filter> elements that the receiver supports or <meta-data> values; see the activity's <intent-filter> and <meta-data> descriptions for more information.
<service>
A Service is a component that can run in the background for an arbitrary amount of time. As with the activity tag, you can optionally include one or more <intent-filter> elements that the service supports or <meta-data> values; see the activity's <intent-filter> and <meta-data> descriptions for more information.
<provider>
A ContentProvider is a component that manages persistent data and publishes it for access by other applications. You can also optionally attach one or more <meta-data> values, as described in the activity's <meta-data> description.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48