From d5368b81857a04879ed55be2a67f034cce4e5094 Mon Sep 17 00:00:00 2001
From: Kevin Hufnagle
-The diagram below shows the general structure of the manifest file and
-every element that it can contain. Each element, along with all of its
-attributes, is documented in full in a separate file. To view detailed
-information about any element, click on the element name in the diagram,
+The diagram below shows the general structure of the manifest file and
+every element that it can contain. Each element, along with all of its
+attributes, is documented in full in a separate file. To view detailed
+information about any element, click on the element name in the diagram,
in the alphabetical list of elements that follows the diagram, or on any
-other mention of the element name.
+other mention of the element name.
-All the elements that can appear in the manifest file are listed below
-in alphabetical order. These are the only legal elements; you cannot
-add your own elements or attributes.
+All the elements that can appear in the manifest file are listed below
+in alphabetical order. These are the only legal elements; you cannot
+add your own elements or attributes.
@@ -158,74 +158,86 @@ add your own elements or attributes.
-Some conventions and rules apply generally to all elements and attributes
+Some conventions and rules apply generally to all elements and attributes
in the manifest:
-If an element contains anything at all, it contains other elements.
+If an element contains anything at all, it contains other elements.
All values are set through attributes, not as character data within an element.
Elements at the same level are generally not ordered. For example,
-Structure of the Manifest File
@@ -126,9 +126,9 @@ other mention of the element name.
File Conventions
<manifest> and
-<application>
-elements are required, they each must be present and can occur only once.
-Most of the others can occur many times or not at all — although at
-least some of them must be present for the manifest to accomplish anything
+<application>
+elements are required, they each must be present and can occur only once.
+Most of the others can occur many times or not at all — although at
+least some of them must be present for the manifest to accomplish anything
meaningful.
<activity>,
-<provider>, and
-<service>
-elements can be intermixed in any sequence. (An
-<activity-alias>
-element is the exception to this rule: It must follow the
-<activity>
-it is an alias for.)
+<activity>,
+<provider>, and
+<service>
+elements can be intermixed in any sequence. There are two key exceptions to this
+rule, however:
+
+
<activity-alias>
+ element must follow the
+ <activity>
+ it is an alias for.
+ <application>
+ element must be the last element inside the
+ <manifest>
+ element. In other words, the </application> closing tag
+ must appear immediately before the </manifest> closing
+ tag.
+
Except for some attributes of the root
-<manifest>
-element, all attribute names begin with an {@code android:} prefix —
-for example, {@code android:alwaysRetainTaskState}. Because the prefix is
-universal, the documentation generally omits it when referring to attributes
+
Except for some attributes of the root
+<manifest>
+element, all attribute names begin with an {@code android:} prefix —
+for example, {@code android:alwaysRetainTaskState}. Because the prefix is
+universal, the documentation generally omits it when referring to attributes
by name.
<application>
-element) and its principal components — activities
-(<activity>),
-services
-(<service>),
-broadcast receivers
-(<receiver>),
-and content providers
-(<provider>).
+<application>
+element) and its principal components — activities
+(<activity>),
+services
+(<service>),
+broadcast receivers
+(<receiver>),
+and content providers
+(<provider>).
-If you define a subclass, as you almost always would for the component classes -({@link android.app.Activity}, {@link android.app.Service}, -{@link android.content.BroadcastReceiver}, and {@link android.content.ContentProvider}), -the subclass is declared through a {@code name} attribute. The name must include -the full package designation. +If you define a subclass, as you almost always would for the component classes +({@link android.app.Activity}, {@link android.app.Service}, +{@link android.content.BroadcastReceiver}, and {@link android.content.ContentProvider}), +the subclass is declared through a {@code name} attribute. The name must include +the full package designation. For example, an {@link android.app.Service} subclass might be declared as follows:
@@ -239,12 +251,12 @@ For example, an {@link android.app.Service} subclass might be declared as follow </manifest>
-However, as a shorthand, if the first character of the string is a period, the
-string is appended to the application's package name (as specified by the
-<manifest>
-element's
-package
-attribute). The following assignment is the same as the one above:
+However, as a shorthand, if the first character of the string is a period, the
+string is appended to the application's package name (as specified by the
+<manifest>
+element's
+package
+attribute). The following assignment is the same as the one above:
<manifest package="com.example.project" . . . > @@ -257,13 +269,13 @@ attribute). The following assignment is the same as the one above: </manifest>
-When starting a component, Android creates an instance of the named subclass. +When starting a component, Android creates an instance of the named subclass. If a subclass isn't specified, it creates an instance of the base class.
<intent-filter . . . > @@ -274,24 +286,24 @@ For example, an intent filter can list several actions: </intent-filter>
{@code @[package:]type/name}
-where the package name can be omitted if the resource is in the same package -as the application, type is a type of resource — such as "string" or -"drawable" — and name is the name that identifies the specific resource. +where the package name can be omitted if the resource is in the same package +as the application, type is a type of resource — such as "string" or +"drawable" — and name is the name that identifies the specific resource. For example:
<activity android:icon="@drawable/smallPic" . . . >
-Values from a theme are expressed in a similar manner, but with an initial '{@code ?}' +Values from a theme are expressed in a similar manner, but with an initial '{@code ?}' rather than '{@code @}':
@@ -299,8 +311,8 @@ rather than '{@code @}':-The following sections describe how some Android features are reflected +The following sections describe how some Android features are reflected in the manifest file.
@@ -316,23 +328,23 @@ in the manifest file.-The core components of an application (its activities, services, and broadcast -receivers) are activated by intents. An intent is a -bundle of information (an {@link android.content.Intent} object) describing a -desired action — including the data to be acted upon, the category of -component that should perform the action, and other pertinent instructions. -Android locates an appropriate component to respond to the intent, launches -a new instance of the component if one is needed, and passes it the +The core components of an application (its activities, services, and broadcast +receivers) are activated by intents. An intent is a +bundle of information (an {@link android.content.Intent} object) describing a +desired action — including the data to be acted upon, the category of +component that should perform the action, and other pertinent instructions. +Android locates an appropriate component to respond to the intent, launches +a new instance of the component if one is needed, and passes it the Intent object.
-Components advertise their capabilities — the kinds of intents they can
-respond to — through intent filters. Since the Android system
-must learn which intents a component can handle before it launches the component,
-intent filters are specified in the manifest as
-<intent-filter>
-elements. A component may have any number of filters, each one describing
+Components advertise their capabilities — the kinds of intents they can
+respond to — through intent filters. Since the Android system
+must learn which intents a component can handle before it launches the component,
+intent filters are specified in the manifest as
+<intent-filter>
+elements. A component may have any number of filters, each one describing
a different capability.
-For information on how Intent objects are tested against intent filters, -see a separate document, -Intents +For information on how Intent objects are tested against intent filters, +see a separate document, +Intents and Intent Filters.
@@ -354,42 +366,42 @@ and Intent Filters.
-A number of elements have {@code icon} and {@code label} attributes for a
-small icon and a text label that can be displayed to users. Some also have a
-{@code description} attribute for longer explanatory text that can also be
-shown on-screen. For example, the
+A number of elements have {@code icon} and {@code label} attributes for a
+small icon and a text label that can be displayed to users. Some also have a
+{@code description} attribute for longer explanatory text that can also be
+shown on-screen. For example, the
<permission>
-element has all three of these attributes, so that when the user is asked whether
-to grant the permission to an application that has requested it, an icon representing
-the permission, the name of the permission, and a description of what it
+element has all three of these attributes, so that when the user is asked whether
+to grant the permission to an application that has requested it, an icon representing
+the permission, the name of the permission, and a description of what it
entails can all be presented to the user.
-In every case, the icon and label set in a containing element become the default
-{@code icon} and {@code label} settings for all of the container's subelements.
-Thus, the icon and label set in the
-<application>
-element are the default icon and label for each of the application's components.
-Similarly, the icon and label set for a component — for example, an
-<activity>
-element — are the default settings for each of the component's
-<intent-filter>
+In every case, the icon and label set in a containing element become the default
+{@code icon} and {@code label} settings for all of the container's subelements.
+Thus, the icon and label set in the
+<application>
+element are the default icon and label for each of the application's components.
+Similarly, the icon and label set for a component — for example, an
+<activity>
+element — are the default settings for each of the component's
+<intent-filter>
elements. If an
-<application>
-element sets a label, but an activity and its intent filter do not,
-the application label is treated as the label for both the activity and
+<application>
+element sets a label, but an activity and its intent filter do not,
+the application label is treated as the label for both the activity and
the intent filter.
-The icon and label set for an intent filter are used to represent a component +The icon and label set for an intent filter are used to represent a component whenever the component is presented to the user as fulfilling the function -advertised by the filter. For example, a filter with -"{@code android.intent.action.MAIN}" and -"{@code android.intent.category.LAUNCHER}" settings advertises an activity +advertised by the filter. For example, a filter with +"{@code android.intent.action.MAIN}" and +"{@code android.intent.category.LAUNCHER}" settings advertises an activity as one that initiates an application — that is, as -one that should be displayed in the application launcher. The icon and label +one that should be displayed in the application launcher. The icon and label set in the filter are therefore the ones displayed in the launcher.
@@ -397,14 +409,14 @@ set in the filter are therefore the ones displayed in the launcher.-A permission is a restriction limiting access to a part of the code -or to data on the device. The limitation is imposed to protect critical -data and code that could be misused to distort or damage the user experience. +A permission is a restriction limiting access to a part of the code +or to data on the device. The limitation is imposed to protect critical +data and code that could be misused to distort or damage the user experience.
-Each permission is identified by a unique label. Often the label indicates -the action that's restricted. For example, here are some permissions defined +Each permission is identified by a unique label. Often the label indicates +the action that's restricted. For example, here are some permissions defined by Android:
@@ -418,26 +430,26 @@ A feature can be protected by at most one permission.
-If an application needs access to a feature protected by a permission,
-it must declare that it requires that permission with a
-<uses-permission>
-element in the manifest. Then, when the application is installed on
-the device, the installer determines whether or not to grant the requested
-permission by checking the authorities that signed the application's
-certificates and, in some cases, asking the user.
-If the permission is granted, the application is able to use the protected
-features. If not, its attempts to access those features will simply fail
-without any notification to the user.
+If an application needs access to a feature protected by a permission,
+it must declare that it requires that permission with a
+<uses-permission>
+element in the manifest. Then, when the application is installed on
+the device, the installer determines whether or not to grant the requested
+permission by checking the authorities that signed the application's
+certificates and, in some cases, asking the user.
+If the permission is granted, the application is able to use the protected
+features. If not, its attempts to access those features will simply fail
+without any notification to the user.
-An application can also protect its own components (activities, services,
-broadcast receivers, and content providers) with permissions. It can employ
-any of the permissions defined by Android (listed in
-{@link android.Manifest.permission android.Manifest.permission}) or declared
-by other applications. Or it can define its own. A new permission is declared
-with the
-<permission>
+An application can also protect its own components (activities, services,
+broadcast receivers, and content providers) with permissions. It can employ
+any of the permissions defined by Android (listed in
+{@link android.Manifest.permission android.Manifest.permission}) or declared
+by other applications. Or it can define its own. A new permission is declared
+with the
+<permission>
element. For example, an activity could be protected as follows:
-Note that, in this example, the {@code DEBIT_ACCT} permission is not only
-declared with the
-<permission>
-element, its use is also requested with the
-<uses-permission>
-element. Its use must be requested in order for other components of the
-application to launch the protected activity, even though the protection
-is imposed by the application itself.
+Note that, in this example, the {@code DEBIT_ACCT} permission is not only
+declared with the
+<permission>
+element, its use is also requested with the
+<uses-permission>
+element. Its use must be requested in order for other components of the
+application to launch the protected activity, even though the protection
+is imposed by the application itself.
-If, in the same example, the {@code permission} attribute was set to a
-permission declared elsewhere
-(such as {@code android.permission.CALL_EMERGENCY_NUMBERS}, it would not
-have been necessary to declare it again with a
-<permission>
-element. However, it would still have been necessary to request its use with
-<uses-permission>.
+If, in the same example, the {@code permission} attribute was set to a
+permission declared elsewhere
+(such as {@code android.permission.CALL_EMERGENCY_NUMBERS}, it would not
+have been necessary to declare it again with a
+<permission>
+element. However, it would still have been necessary to request its use with
+<uses-permission>.
-The
-<permission-tree>
-element declares a namespace for a group of permissions that will be defined in
-code. And
+The
+<permission-tree>
+element declares a namespace for a group of permissions that will be defined in
+code. And
<permission-group>
-defines a label for a set of permissions (both those declared in the manifest with
-<permission>
-elements and those declared elsewhere). It affects only how the permissions are
-grouped when presented to the user. The
+defines a label for a set of permissions (both those declared in the manifest with
+<permission>
+elements and those declared elsewhere). It affects only how the permissions are
+grouped when presented to the user. The
<permission-group>
-element does not specify which permissions belong to the group;
+element does not specify which permissions belong to the group;
it just gives the group a name. A permission is placed in the group
by assigning the group name to the
-<permission>
-element's
-permissionGroup
+<permission>
+element's
+permissionGroup
attribute.
-Every application is linked against the default Android library, which -includes the basic packages for building applications (with common classes -such as Activity, Service, Intent, View, Button, Application, ContentProvider, +Every application is linked against the default Android library, which +includes the basic packages for building applications (with common classes +such as Activity, Service, Intent, View, Button, Application, ContentProvider, and so on).
-However, some packages reside in their own libraries. If your application
-uses code from any of these packages, it must explicitly asked to be linked
-against them. The manifest must contain a separate
-<uses-library>
-element to name each of the libraries. (The library name can be found in the
+However, some packages reside in their own libraries. If your application
+uses code from any of these packages, it must explicitly asked to be linked
+against them. The manifest must contain a separate
+<uses-library>
+element to name each of the libraries. (The library name can be found in the
documentation for the package.)