每个应用程序在它的根目录中都必须要有一个AndroidManifest.xml(名字须精确一致)文件。这个清单把应用程序的基本信息提交给Android系统,在应用程序的代码能够运行之前,这个信息系统必须建立。以下项目是清单文件所需要完成的工作:
【注】:这个文件是需要程序员手动配置的,所以了解它的作用和结构很有必要。
官网原文如下:
Intent
messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched.Instrumentation
classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they‘re removed before the application is published.下图显示的是清单文件的一般结构和它所能包含的所有元素。每一个元素以及它们的所有属性都在官方的单独文档中介绍。
<?xml version="1.0" encoding="utf-8"?> <manifest>
<uses-permission /> <permission /> <permission-tree /> <permission-group /> <instrumentation /> <uses-sdk /> <uses-configuration /> <uses-feature /> <supports-screens /> <compatible-screens /> <supports-gl-texture /> <application> <activity> <intent-filter> <action /> <category /> <data /> </intent-filter> <meta-data /> </activity> <activity-alias> <intent-filter> . . . </intent-filter> <meta-data /> </activity-alias> <service> <intent-filter> . . . </intent-filter> <meta-data/> </service> <receiver> <intent-filter> . . . </intent-filter> <meta-data /> </receiver> <provider> <grant-uri-permission /> <meta-data /> <path-permission /> </provider> <uses-library /> </application> </manifest>
我们把上图所有出现过的元素按字符顺序排列如下(顺便把官方链接也拷贝过来了):
<action>
<activity>
<activity-alias>
<application>
<category>
<data>
<grant-uri-permission>
<instrumentation>
<intent-filter>
<manifest>
<meta-data>
<permission>
<permission-group>
<permission-tree>
<provider>
<receiver>
<service>
<supports-screens>
<uses-configuration>
<uses-feature>
<uses-library>
<uses-permission>
<uses-sdk>
AndroidManifest.xml文件中的元素和属性需要遵守一些约定和规则:
只用<manifest>和<application>元素是必须的,而且这两个元素在文件中只能出现一次。其他元素则可以多次出现在清单中,或者根本就不出现---但是为了构建一个有意义的清单,必须要在清单中声明某些元素。如果一个元素包含了一切,它包含了其他元素(If an element contains anything at all, it contains other elements)。所有的值都是通过属性来设置的,而不是用夹在开闭元素之间的字符数据。相同级别的元素通常是没有顺序的。例如,<activity>、<provider>、<service>元素可以是任意顺序的。(<activity-alias>元素是个例外,它必须放在它所代表的<activity>元素的后面。)
在正式的含义中,所有的属性都是可选的,但是,为了达成目的,必须要给元素指定一些属性。对于真正的可选属性,会指定发生在特殊情况下的默认值或状态。除了<manifest>根元素的一些属性之外,其他所有属性的命名都带有android:前缀---例如,android:alwaysRetainTaskState。因为这个前缀是通用的,所以本文档在提到属性名时,通常会忽略这个前缀。
[安卓]AndroidManifest.xml文件简介及结构
原文:http://www.cnblogs.com/victor-ma/p/4371321.html