1page.title=App Manifest 2@jd:body 3 4<div id="qv-wrapper"> 5<div id="qv"> 6 7<h2>In this document</h2> 8<ol> 9<li><a href="#filestruct">Manifest file structure</a></li> 10<li><a href="#filec">File conventions</a> 11<li><a href="#filef">File features</a> 12 <ol> 13 <li><a href="#ifs">Intent filters</a></li> 14 <li><a href="#iconlabel">Icons and labels</a></li> 15 <li><a href="#perms">Permissions</a></li> 16 <li><a href="#libs">Libraries</a></li> 17 </ol></li> 18</ol> 19</div> 20</div> 21 22<p> 23 Every application must have an {@code AndroidManifest.xml} file (with precisely that 24 name) in its root directory. <span itemprop="description">The manifest file 25 provides essential information about your app to the Android system, which 26 the system must have before it can run any of the app's 27 code.</span> 28</p> 29 30<p> 31Among other things, the manifest file does the following: 32</p> 33 34<ul> 35<li>It names the Java package for the application. 36The package name serves as a unique identifier for the application.</li> 37 38<li>It describes the components of the application, which include the activities, 39services, broadcast receivers, and content providers that compose the application. 40It also names the classes that implement each of the components and 41publishes their capabilities, such as the {@link android.content.Intent 42Intent} messages that they can handle. These declarations inform the Android system 43of the components and the conditions in which they can be launched.</li> 44 45<li>It determines the processes that host the application components.</li> 46 47<li>It declares the permissions that the application must have in order to 48access protected parts of the API and interact with other applications. It also declares 49the permissions that others are required to have in 50order to interact with the application's components.</li> 51 52<li>It lists the {@link android.app.Instrumentation} classes that provide 53profiling and other information as the application runs. These declarations 54are present in the manifest only while the application is being developed and 55are removed before the application is published.</li> 56 57<li>It declares the minimum level of the Android API that the application 58requires.</li> 59 60<li>It lists the libraries that the application must be linked against.</li> 61</ul> 62 63<p class="note"><strong>Note</strong>: As you prepare your Android app to run on Chromebooks, 64there are some important hardware and software feature limitations that you should consider. See 65the <a href="{@docRoot}topic/arc/manifest.html"> 66App Manifest Compatibility for Chromebooks</a> document for more information. 67</p> 68 69<h2 id="filestruct">Manifest file structure</h2> 70 71<p> 72The code snippet below shows the general structure of the manifest file and 73every element that it can contain. Each element, along with all of its 74attributes, is fully documented in a separate file. 75</p> 76 77<p class="note"><strong>Tip</strong>: To view detailed 78information about any of the elements that are mentioned within the text of this document, 79simply click the element name. 80</p> 81 82<p> 83Here is an example of the manifest file: 84</p> 85 86<pre> 87<?xml version="1.0" encoding="utf-8"?> 88 89<a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a> 90 91 <a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission /></a> 92 <a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission /></a> 93 <a href="{@docRoot}guide/topics/manifest/permission-tree-element.html"><permission-tree /></a> 94 <a href="{@docRoot}guide/topics/manifest/permission-group-element.html"><permission-group /></a> 95 <a href="{@docRoot}guide/topics/manifest/instrumentation-element.html"><instrumentation /></a> 96 <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><uses-sdk /></a> 97 <a href="{@docRoot}guide/topics/manifest/uses-configuration-element.html"><uses-configuration /></a> <!-- ##api level 3## --> 98 <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature /></a> <!-- ##api level 4## --> 99 <a href="{@docRoot}guide/topics/manifest/supports-screens-element.html"><supports-screens /></a> <!-- ##api level 4## --> 100 <a href="{@docRoot}guide/topics/manifest/compatible-screens-element.html"><compatible-screens /></a> <!-- ##api level 9## --> 101 <a href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html"><supports-gl-texture /></a> <!-- ##api level 11## --> 102 103 <a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a> 104 105 <a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a> 106 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a> 107 <a href="{@docRoot}guide/topics/manifest/action-element.html"><action /></a> 108 <a href="{@docRoot}guide/topics/manifest/category-element.html"><category /></a> 109 <a href="{@docRoot}guide/topics/manifest/data-element.html"><data /></a> 110 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"></intent-filter></a> 111 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data /></a> 112 <a href="{@docRoot}guide/topics/manifest/activity-element.html"></activity></a> 113 114 <a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"><activity-alias></a> 115 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a> . . . <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"></intent-filter></a> 116 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data /></a> 117 <a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"></activity-alias></a> 118 119 <a href="{@docRoot}guide/topics/manifest/service-element.html"><service></a> 120 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a> . . . <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"></intent-filter></a> 121 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data/></a> 122 <a href="{@docRoot}guide/topics/manifest/service-element.html"></service></a> 123 124 <a href="{@docRoot}guide/topics/manifest/receiver-element.html"><receiver></a> 125 <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a> . . . <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"></intent-filter></a> 126 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data /></a> 127 <a href="{@docRoot}guide/topics/manifest/receiver-element.html"></receiver></a> 128 129 <a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a> 130 <a href="{@docRoot}guide/topics/manifest/grant-uri-permission-element.html"><grant-uri-permission /></a> 131 <a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data /></a> 132 <a href="{@docRoot}guide/topics/manifest/path-permission-element.html"><path-permission /></a> 133 <a href="{@docRoot}guide/topics/manifest/provider-element.html"></provider></a> 134 135 <a href="{@docRoot}guide/topics/manifest/uses-library-element.html"><uses-library /></a> 136 137 <a href="{@docRoot}guide/topics/manifest/application-element.html"></application></a> 138 139<a href="{@docRoot}guide/topics/manifest/manifest-element.html"></manifest></a> 140</pre> 141 142<p> 143The following list contains all of the elements that can appear in the manifest file, 144in alphabetical order: 145</p> 146 147<ul> 148 <li><code><a href="{@docRoot}guide/topics/manifest/action-element.html"><action></a></code></li> 149 <li><code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code></li> 150 <li><code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"><activity-alias></a></code></li> 151 <li><code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code></li> 152 <li><code><a href="{@docRoot}guide/topics/manifest/category-element.html"><category></a></code></li> 153 <li><code><a href="{@docRoot}guide/topics/manifest/data-element.html"><data></a></code></li> 154 <li><code><a href="{@docRoot}guide/topics/manifest/grant-uri-permission-element.html"><grant-uri-permission></a></code></li> 155 <li><code><a href="{@docRoot}guide/topics/manifest/instrumentation-element.html"><instrumentation></a></code></li> 156 <li><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code></li> 157 <li><code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code></li> 158 <li><code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data></a></code></li> 159 <li><code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code></li> 160 <li><code><a href="{@docRoot}guide/topics/manifest/permission-group-element.html"><permission-group></a></code></li> 161 <li><code><a href="{@docRoot}guide/topics/manifest/permission-tree-element.html"><permission-tree></a></code></li> 162 <li><code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code></li> 163 <li><code><a href="{@docRoot}guide/topics/manifest/receiver-element.html"><receiver></a></code></li> 164 <li><code><a href="{@docRoot}guide/topics/manifest/service-element.html"><service></a></code></li> 165 <li><code><a href="{@docRoot}guide/topics/manifest/supports-screens-element.html"><supports-screens></a></code> <!-- ##api level 4## --></li> 166 <li><code><a href="{@docRoot}guide/topics/manifest/uses-configuration-element.html"><uses-configuration></a></code> <!-- ##api level 3## --></li> 167 <li><code><a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a></code> <!-- ##api level 4## --></li> 168 <li><code><a href="{@docRoot}guide/topics/manifest/uses-library-element.html"><uses-library></a></code></li> 169 <li><code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code></li> 170 <li><code><a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><uses-sdk></a></code></li> 171</ul> 172 173<p class="note"><strong>Note</strong>: These are the only legal elements – you cannot 174add your own elements or attributes. 175</p> 176 177<h2 id="filec">File conventions</h2> 178 179<p> 180This section describes the conventions and rules that apply generally to all of the elements and 181attributes in the manifest file. 182</p> 183 184<dl> 185<dt><b>Elements</b></dt> 186<dd>Only the 187<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> and 188<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 189elements are required. They each must be present and can occur only once. 190Most of the other elements can occur many times or not at all. However, at 191least some of them must be present before the manifest file becomes useful. 192 193<p> 194If an element contains anything at all, it contains other elements. 195All of the values are set through attributes, not as character data within an element. 196</p> 197 198<p> 199Elements at the same level are generally not ordered. For example, the 200<code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code>, 201<code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code>, and 202<code><a href="{@docRoot}guide/topics/manifest/service-element.html"><service></a></code> 203elements can be intermixed in any sequence. There are two key exceptions to this 204rule: 205<ul> 206 <li> 207 An <code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"><activity-alias></a></code> 208 element must follow the 209 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> 210 for which it is an alias. 211 </li> 212 <li> 213 The <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 214 element must be the last element inside the 215 <code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> 216 element. In other words, the <code></application></code> closing tag 217 must appear immediately before the <code></manifest></code> closing 218 tag. 219 </li> 220</p></dd> 221 222<dt><b>Attributes</b></dt> 223<dd>In a formal sense, all attributes are optional. However, there are some attributes 224that must be specified so that an element can accomplish its purpose. Use the 225documentation as a guide. For truly optional attributes, it mentions a default 226value or states what happens in the absence of a specification. 227 228<p>Except for some attributes of the root 229<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> 230element, all attribute names begin with an {@code android:} prefix. 231For example, {@code android:alwaysRetainTaskState}. Because the prefix is 232universal, the documentation generally omits it when referring to attributes 233by name.</p></dd> 234 235<dt><b>Declaring class names</b></dt> 236<dd>Many elements correspond to Java objects, including elements for the 237application itself (the 238<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 239element) and its principal components: activities 240(<code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code>), 241services 242(<code><a href="{@docRoot}guide/topics/manifest/service-element.html"><service></a></code>), 243broadcast receivers 244(<code><a href="{@docRoot}guide/topics/manifest/receiver-element.html"><receiver></a></code>), 245and content providers 246(<code><a href="{@docRoot}guide/topics/manifest/provider-element.html"><provider></a></code>). 247 248<p> 249If you define a subclass, as you almost always would for the component classes 250({@link android.app.Activity}, {@link android.app.Service}, 251{@link android.content.BroadcastReceiver}, and {@link android.content.ContentProvider}), 252the subclass is declared through a {@code name} attribute. The name must include 253the full package designation. 254For example, a {@link android.app.Service} subclass might be declared as follows: 255</p> 256 257<pre><manifest . . . > 258 <application . . . > 259 <service android:name="com.example.project.SecretService" . . . > 260 . . . 261 </service> 262 . . . 263 </application> 264</manifest></pre> 265 266<p> 267However, if the first character of the string is a period, the 268application's package name (as specified by the 269<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> 270element's 271<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html#package">package</a></code> 272attribute) is appended to the string. The following assignment is the same as that shown above: 273</p> 274 275<pre><manifest package="com.example.project" . . . > 276 <application . . . > 277 <service android:name=".SecretService" . . . > 278 . . . 279 </service> 280 . . . 281 </application> 282</manifest></pre> 283 284<p> 285When starting a component, the Android system creates an instance of the named subclass. 286If a subclass isn't specified, it creates an instance of the base class. 287</p></dd> 288 289<dt><b>Multiple values</b></dt> 290<dd>If more than one value can be specified, the element is almost always 291repeated, rather than multiple values being listed within a single element. 292For example, an intent filter can list several actions: 293 294<pre><intent-filter . . . > 295 <action android:name="android.intent.action.EDIT" /> 296 <action android:name="android.intent.action.INSERT" /> 297 <action android:name="android.intent.action.DELETE" /> 298 . . . 299</intent-filter></pre></dd> 300 301<dt><b>Resource values</b></dt> 302<dd>Some attributes have values that can be displayed to users, such as 303a label and an icon for an activity. The values of these attributes 304should be localized and set from a resource or theme. Resource 305values are expressed in the following format:</p> 306 307<p style="margin-left: 2em">{@code @[<i>package</i>:]<i>type</i>/<i>name</i>}</p> 308 309<p> 310You can ommit the <i>package</i> name if the resource is in the same package 311as the application. The <i>type</i> is a type of resource, such as <em>string</em> or 312<em>drawable</em>, and the <i>name</i> is the name that identifies the specific resource. 313Here is an example: 314</p> 315 316<pre><activity android:icon="@drawable/smallPic" . . . ></pre> 317 318<p> 319The values from a theme are expressed similarly, but with an initial {@code ?} 320instead of {@code @}: 321</p> 322 323<p style="margin-left: 2em">{@code ?[<i>package</i>:]<i>type</i>/<i>name</i>} 324</p></dd> 325 326<dt><b>String values</b></dt> 327<dd>Where an attribute value is a string, you must use double backslashes ({@code \\}) 328to escape characters, such as {@code \\n} for 329a newline or {@code \\uxxxx} for a Unicode character.</dd> 330</dl> 331 332<h2 id="filef">File features</h2> 333 334<p> 335The following sections describe the way that some Android features are reflected 336in the manifest file. 337</p> 338 339 340<h3 id="ifs">Intent filters</h3> 341 342<p> 343The core components of an application, such as its activities, services, and broadcast 344receivers, are activated by <i>intents</i>. An intent is a 345bundle of information (an {@link android.content.Intent} object) describing a 346desired action, including the data to be acted upon, the category of 347component that should perform the action, and other pertinent instructions. 348The Android system locates an appropriate component that can respond to the intent, launches 349a new instance of the component if one is needed, and passes it the 350{@link android.content.Intent} object. 351</p> 352 353<p> 354The components advertise the types of intents that they can 355respond to through <i>intent filters</i>. Since the Android system 356must learn the intents that a component can handle before it launches the component, 357intent filters are specified in the manifest as 358<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> 359elements. A component can have any number of filters, each one describing 360a different capability. 361</p> 362 363<p> 364An intent that explicitly names a target component activates that component, so 365the filter doesn't play a role. An intent that doesn't specify a target by 366name can activate a component only if it can pass through one of the component's 367filters. 368</p> 369 370<p> 371For information about how {@link android.content.Intent} objects are tested against intent filters, 372see the <a href="{@docRoot}guide/components/intents-filters.html">Intents 373and Intent Filters</a> document. 374</p> 375 376<h3 id="iconlabel">Icons and labels</h3> 377 378<p> 379A number of elements have {@code icon} and {@code label} attributes for a 380small icon and a text label that can be displayed to users. Some also have a 381{@code description} attribute for longer, explanatory text that can also be 382shown on-screen. For example, the 383<code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 384element has all three of these attributes so that when the user is asked whether 385to grant the permission to an application that has requested it, an icon representing 386the permission, the name of the permission, and a description of what it 387entails are all presented to the user. 388</p> 389 390<p> 391In every case, the icon and label that are set in a containing element become the default 392{@code icon} and {@code label} settings for all of the container's subelements. 393Thus, the icon and label that are set in the 394<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 395element are the default icon and label for each of the application's components. 396Similarly, the icon and label that are set for a component, such as an 397<code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> 398element, are the default settings for each of the component's 399<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> 400elements. If an 401<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 402element sets a label, but an activity and its intent filter do not, 403the application label is treated as the label for both the activity and 404the intent filter. 405</p> 406 407<p> 408The icon and label that are set for an intent filter represent a component 409whenever the component is presented to the user and fulfills the function 410that is advertised by the filter. For example, a filter with 411{@code android.intent.action.MAIN} and 412{@code android.intent.category.LAUNCHER} settings advertises an activity 413as one that initiates an application. That is, as 414one that should be displayed in the application launcher. The icon and label 415that are set in the filter are displayed in the launcher. 416</p> 417 418<h3 id="perms">Permissions</h3> 419 420<p> 421A <i>permission</i> is a restriction that limits access to a part of the code 422or to data on the device. The limitation is imposed to protect critical 423data and code that could be misused to distort or damage the user experience. 424</p> 425 426<p> 427Each permission is identified by a unique label. Often the label indicates 428the action that's restricted. Here are some permissions that are defined 429by Android: 430</p> 431 432<ul> 433 <li>{@code android.permission.CALL_EMERGENCY_NUMBERS}</li> 434 <li>{@code android.permission.READ_OWNER_DATA}</li> 435 <li>{@code android.permission.SET_WALLPAPER}</li> 436 <li>{@code android.permission.DEVICE_POWER}</li> 437</ul> 438 439<p> 440A feature can be protected by only one permission. 441</p> 442 443<p> 444If an application needs access to a feature that is protected by a permission, 445it must declare that it requires the permission with a 446<code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code> 447element in the manifest. When the application is installed on 448the device, the installer determines whether to grant the requested 449permission by checking the authorities that signed the application's 450certificates and, in some cases, asking the user. 451If the permission is granted, the application is able to use the protected 452features. If not, its attempts to access those features fail 453without any notification to the user. 454</p> 455 456<p> 457An application can also protect its own components with permissions. It can employ 458any of the permissions that are defined by Android, as listed in 459{@link android.Manifest.permission android.Manifest.permission}, or declared 460by other applications. It can also define its own. A new permission is declared 461with the 462<code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 463element. For example, an activity could be protected as follows: 464</p> 465 466<pre> 467<manifest . . . > 468 <permission android:name="com.example.project.DEBIT_ACCT" . . . /> 469 <uses-permission android:name="com.example.project.DEBIT_ACCT" /> 470 . . . 471 <application . . .> 472 <activity android:name="com.example.project.FreneticActivity" 473 android:permission="com.example.project.DEBIT_ACCT" 474 . . . > 475 . . . 476 </activity> 477 </application> 478</manifest> 479</pre> 480 481<p> 482Note that, in this example, the {@code DEBIT_ACCT} permission is not only 483declared with the 484<code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 485element, its use is also requested with the 486<code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code> 487element. You must request its use in order for other components of the 488application to launch the protected activity, even though the protection 489is imposed by the application itself. 490</p> 491 492<p> 493If, in the same example shown above, the {@code permission} attribute was set to a 494permission that is declared elsewhere, 495such as {@code android.permission.CALL_EMERGENCY_NUMBERS}, it would not 496be necessary to declare it again with a 497<code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 498element. However, it would still be necessary to request its use with 499<code><a href="{@docRoot}guide/topics/manifest/uses-permission-element.html"><uses-permission></a></code>. 500</p> 501 502<p> 503The 504<code><a href="{@docRoot}guide/topics/manifest/permission-tree-element.html"><permission-tree></a></code> 505element declares a namespace for a group of permissions that are defined in 506code, and the 507<code><a href="{@docRoot}guide/topics/manifest/permission-group-element.html"><permission-group></a></code> 508defines a label for a set of permissions, both those declared in the manifest with 509<code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 510elements and those declared elsewhere. This affects only how the permissions are 511grouped when presented to the user. The 512<code><a href="{@docRoot}guide/topics/manifest/permission-group-element.html"><permission-group></a></code> 513element does not specify the permissions that belong to the group, but 514it gives the group a name. You can place a permission in the group 515by assigning the group name to the 516<code><a href="{@docRoot}guide/topics/manifest/permission-element.html"><permission></a></code> 517element's 518<code><a href="{@docRoot}guide/topics/manifest/permission-element.html#pgroup">permissionGroup</a></code> 519attribute. 520</p> 521 522 523<h3 id="libs">Libraries</h3> 524 525<p> 526Every application is linked against the default Android library, which 527includes the basic packages for building applications (with common classes 528such as Activity, Service, Intent, View, Button, Application, and ContentProvider). 529</p> 530 531<p> 532However, some packages reside in their own libraries. If your application 533uses code from any of these packages, it must explicitly ask to be linked 534against them. The manifest must contain a separate 535<code><a href="{@docRoot}guide/topics/manifest/uses-library-element.html"><uses-library></a></code> 536element to name each of the libraries. You can find the library name in the 537documentation for the package. 538</p> 539