AndroidManifest.xml文件处于Android工程的最高层,它包含标识应用程序身份的重要信息,其中包括应用程序名称、版本信息和应用程序所依赖的应用程序组件 , 以及应用程序运行所需的许可权限和其他应用程序配置信息。
下面先来一个典型的例子:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="zyl.androidtest.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:debuggable="true" >
<activity
android:label="@string/app_name"
android:name=".HelloAndroidActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在manifest文件中可完成的功能有:
1. 标志应用程序身份: 版本号、名称和图标
2. 注册Activity 和其他应用程序组件 : 在<activity android:name="ActivityName" />中完成注册;
_可使用Intent filter 为程序指派主入口点Activity, 如
<activity
android:name=".MainMenuActivity"
android:label="@string/app_name"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
_可配置其它Intent 过滤器:
_注册Service和BroadcastReceiver: 分别用<service> 和 <receiver>标记注册,均使用Intent过滤器;
3. 使用许可权限:
_注册程序所需许可权限: <uses-permission android:name="android.permission.CAMERA" />
_注册程序许可权限: <permission>用于定义属于程序自身的许可权限, 必须用android.permission属性进行描述,且授予特定的程序组件,如Activity;
注: 许可权限在若干个点被强制验证-- 当启动一个Activity或Service时;当访问由Content provider 提供的数据时;当处在函数调用层时;当发送和接收Intent广播时。 许可权限可有3种主要保护级别: normal(正常)、dangerous(危险)和signature(签名)。
_在Uri层级上增强内容提供者权限: 用<grant-uri-permission>标记引入
4. 指定程序所需输入设备和软件: <uses-configuration android:reqTouchScreen="finger" /> 表示只需要用手指输入即可
5. 指定所需库和Android SDK 版本: <uses-sdk> 和 <uses-library>两个标签
综述:
总的来说manifest文件主要是用于顶层描述和组织整个工程的工具, 在其中主要有两个域<application> (应用程序域,必须)和<instrumentation>(检测设置, optional)。