定义:AndrodiManifest.xml文件为Android程序的入口文件,而且是必须的,位于整个项目的根目录下。拿到一个Android项目,能够先从AndroidManifest.xml文件入手,进行分析。它提供了一些必要的信息,好比程序的入口Activity,其余组件的声明,权限的声明,包名,版本信息等。php
Manifest能够作如下事情:android
<?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>复制代码
清单文件的根元素,必须包含标签,指定命名空间xmlns:android和package属性app
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="string" android:sharedUserId="string" android:sharedUserLabel="string resource" android:versionCode="integer" android:versionName="string" android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
. . .
</manifest>复制代码
xmlns:android,定义android命名空间,一般设置为“schemas.android.com/apk/res/and… 关于xml的命名空间,能够看这里ide
package:不一样的APP具备不一样的包名。以Java包名风格进行命名,必须惟一。性能
sharedUserId:具备相同的uderId而且具备相同签名的APP能够共享和访问彼此的数据,甚至能够在同一个进程里面运行,此时必须设置相同。测试
sharedUserLabel:给共享userId定义了用户可读标签,只有设置了sharedUserId,此属性才有意义。ui
versionCode:内部版本号。必须是整数,Integer类型。用来判断版本的升级,每一次发布都必须必以前的要大。若是versionName没有设置,则设置成此值。spa
versionName:展现给用户看的版本号。为String类型。设计
installLocation:设置apk文件的默认安装路径。code
声明APP须要使用到的权限,Android5.1或如下在安装的时候声请,Android6.0或以上的须要运行时权限申请
<uses-permission android:name="string" android:maxSdkVersion="integer" />复制代码
name:权限的名称。能够是系统定义的权限,也能够是其余应用的权限,或者是使用自定义的权限
maxSdkVersion:此申请的权限最高的做用Android版本。当一些权限在高版本无需申请的时候能够设置此值,好比 WRITE_EXTERNAL_STORAGE,在API 19就不须要进行申请了,能够进行以下操做
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />复制代码
自定义权限,以限制访问指定的组件或APP——本APP或其余APP,起到保护的做用。
<permission android:description="string resource" android:icon="drawable resource" android:label="string resource" android:name="string" android:permissionGroup="string" android:protectionLevel=["normal" | "dangerous" | "signature" | "signatureOrSystem"] />复制代码
description:自定义的用户可读的权限描述,
icon:权限的icon图标
label:展现给用户的权限名字
name:权限的命名,为一串惟一的英文字符,如:com.example.READ_ACTIVITY。须要注意的是Android系统不容许不一样的包名定义相同的权限名(permission name),除非不一样的包名具备相同的签名证书。若是一个APP1声明了权限名A,则系统不容许另一个声明了权限名A的不一样签名证书的APP2进行安装。为了不这种状况发生,能够以本身APP的包名为前缀进行权限声明
permissionGroup:权限所属的权限组,此项的值必须为中声明的name或者是其余APP声明的。若是此项不设置,则此权限不属于权限组。
protectionLevel:权限的级别。
要访问授权限保护的组件,必须在进行声明,不管是官方定义的仍是自定义的,如:
<manifest>
<permission android:name="com.example.READ_ACTIVITY"/>
<uses-permission android:name="com.example.READ_ACTIVITY" />
<application>
<activity android:name="com.example.TestActivity" android:permission="com.example.READ_ACTIVITY" >
</activity>
</application>
</manifest>复制代码
TestActivity声明了READ_ACTIVITY权限保护,若是要启动TestActivity,必需要申请READ_ACTIVITY权限
声明一个权限树,能够在此节点上动态添加权限,PackageManager.addPermission()。如声明了权限树com.example.project.taxes,在此节点上能够动态添加权限:
com.example.project.taxes.CALCULATE
com.example.project.taxes.deductions.MAKE_SOME_UP
com.example.project.taxes.deductions.EXAGGERATE
须要注意的是此项声明的不是权限,是权限的命名空间。
<permission-tree android:icon="drawable resource" android:label="string resource" ] android:name="string" />复制代码
icon和label与permission的相似。
name为权限的命名,如:com.example.project.taxes
声明一个逻辑上的权限分组
<permission-group android:description="string resource" android:icon="drawable resource" android:label="string resource" android:name="string" />复制代码
声明一个Instrumentation类,用来监控APP和系统的交互。Instrumentation对象会在APP的全部组件以前进行实例化。
<instrumentation android:functionalTest=["true" | "false"] android:handleProfiling=["true" | "false"] android:icon="drawable resource" android:label="string resource" android:name="string" android:targetPackage="string" />复制代码
functionalTest:是否进行功能性的测试。true:是。false:否。默认值为false
handleProfiling:true:自定义性能分析的开始和结束时间。false:性能分析整个运行过程。默认值为false
name:Instrumentation子类的全名。好比:com.example.project.StringInstrumentation
targetPackage:Instrumentation对象所依赖的目标包名
<uses-sdk android:minSdkVersion="integer" android:targetSdkVersion="integer" android:maxSdkVersion="integer" />复制代码
minSdkVersion:指定APP运行的所需最低API级别的整数,若是系统API级别低于此值,则会阻止用户安装。若是不声明该属性,则默认为1。
targetSdkVersion:指定APP目标API级别的整数,不过不声明该属性,则默认和minSdkVersion同样
maxSdkVersion:APP可以运行在系统的最大API级别。在Android2.0.1如下,若是APP指定的此项低于系统的API级别,则会安装不了,已安装的会被隐藏掉。Android2.0.1(不包含)以上的系统不会检查安装的APP的此项属性,因此不会出现2.0.1如下的状况。此值通常不进行设置。
用来设置APP须要的相关硬件和软件的配置。大部分APP都不须要此属性。
<uses-configuration android:reqFiveWayNav=["true" | "false"] android:reqHardKeyboard=["true" | "false"] android:reqKeyboardType=["undefined" | "nokeys" | "qwerty" | "twelvekey"] android:reqNavigation=["undefined" | "nonav" | "dpad" | "trackball" | "wheel"] android:reqTouchScreen=["undefined" | "notouch" | "stylus" | "finger"] />复制代码
reqFiveWayNav:是否须要五维导航控制,如方向版(D-pad),轨迹球等。
reqHardKeyboard:是否须要物理键盘
reqKeyboardType:设置所需键盘的类型
reqNavigation:指定方向控制的确切类型或不指定(undefined,为默认值)
reqTouchScreen:触摸屏的类型。
用来声明APP所要使用和依赖的单一的软硬件功能。该项所提供的require属性若是是须要的功能,那么若是缺乏的话就会没法使用。好比声明了<uses-feature android:name="android.hardware.camera" require="true"/>,若是缺乏摄像头,那么就会没法使用。而且必须单独地为每一个功能进行声明。很重要的一点是GooglePlay会根据此项所声明的功能进行过滤提供给兼容设备的用户,用户只能下载和其设备相容的APP。
<uses-feature android:name="string" android:required=["true" | "false"] android:glEsVersion="integer" />复制代码
name:硬件或软件功能的字符串描述。
required:true,当设备没有改指定的功能(name)时,APP没法正常工做或设计为没法正常工做;false,有该功能优先使用该功能,无也可正常工做。默认值为true
glEsVersion:所须要的OpenGL ES版本。高16位表示主版本号,底16位表示次版本号。例如,要指定 OpenGL ES 2.0 版,您须要将其值设置为“0x00020000”;要指定 OpenGL ES 3.2,则需将其值设置为“0x00030002”。若是声明多个,则选择最高版本的那个,其它的忽略。若是不声明,则默认为1.0版本,全部Android设备都支持。