AndroidManifest.xml元素详解

<?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 配置 -->
        <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>
        
        <activity-alias>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </activity-alias>
        
        <!-- Service 配置 -->
        <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>
        
        <!-- Receiver 配置 -->
        <receiver>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </receiver>
        
        <!-- Provider 配置 -->
        <provider>
            <grant-uri-permission />
            <meta-data />
        </provider>
        
        <!-- 所需类库配置 -->
        <uses-library />

    </application>

</manifest>



1. <manifest> </manifest>

<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>
   它必须包含以下两个属性:

   1) xmlns:android

   2) package

2. <uses-permission />申请权限

<uses-permission android:name="string" />
   申请程序正常运行所必须的权限,在安装时由用户授予。

   android:name可以其它应用程序通过<permission />定义的权限;也可以是系统定义的权限,如:

   "android.permission.CAMERA" or "android.permission.READ_CONTACTS"

3. <permission />定义权限

<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"] />

4. <uses-sdk />

<uses-sdk android:minSdkVersion="integer"
          android:targetSdkVersion="integer"
          android:maxSdkVersion="integer" />
  "interger"为API Level。

5. <supports-screens />  

<supports-screens android:resizeable=["true"| "false"]
                  android:smallScreens=["true" | "false"]
                  android:normalScreens=["true" | "false"]
                  android:largeScreens=["true" | "false"]
                  android:xlargeScreens=["true" | "false"]
                  android:anyDensity=["true" | "false"]
                  android:requiresSmallestWidthDp="integer"
                  android:compatibleWidthLimitDp="integer"
                  android:largestWidthLimitDp="integer"/>


6. <compatible-screens>   </compatible-screens>

<compatible-screens>
    <screen android:screenSize=["small" | "normal" | "large" | "xlarge"]
            android:screenDensity=["ldpi" | "mdpi" | "hdpi" | "xhdpi"] />
    ...
</compatible-screens>
    Android系统在安装或运行时,都不会读取<compatible-screens>元素。此元素被外部服务(如Google Play)使用,以更好地理解应用程序与屏幕配置的兼容性,并且为用户进行过滤。示例如下:  

<manifest ... >
    ...
    <compatible-screens>
        <!-- all small size screens -->
        <screen android:screenSize="small" android:screenDensity="ldpi" />
        <screen android:screenSize="small" android:screenDensity="mdpi" />
        <screen android:screenSize="small" android:screenDensity="hdpi" />
        <screen android:screenSize="small" android:screenDensity="xhdpi" />
        <!-- all normal size screens -->
        <screen android:screenSize="normal" android:screenDensity="ldpi" />
        <screen android:screenSize="normal" android:screenDensity="mdpi" />
        <screen android:screenSize="normal" android:screenDensity="hdpi" />
        <screen android:screenSize="normal" android:screenDensity="xhdpi" />
    </compatible-screens>
    <application ... >
        ...
    <application>
</manifest>


7. <supports-gl-texture />

<supports-gl-texture
  android:name="string" />
    宣布应用程序支持“a single GL texture compression format”,应用程序可以提供本地的压缩资源(在.apk中),或应用程序在运行时从服务器下载。实例如下:

<supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture" />
<supports-gl-texture android:name="GL_OES_compressed_paletted_texture" />
   android:name可使用的值如下表所示:



8. <application> </application>

<application android:allowTaskReparenting=["true" | "false"]
             android:allowBackup=["true" | "false"]
             android:backupAgent="string"
             android:debuggable=["true" | "false"]
             android:description="string resource"
             android:enabled=["true" | "false"]
             android:hasCode=["true" | "false"]
             android:hardwareAccelerated=["true" | "false"]
             android:icon="drawable resource"
             android:killAfterRestore=["true" | "false"]
             android:largeHeap=["true" | "false"]
             android:label="string resource"
             android:logo="drawable resource"
             android:manageSpaceActivity="string"
             android:name="string"
             android:permission="string"
             android:persistent=["true" | "false"]
             android:process="string"
             android:restoreAnyVersion=["true" | "false"]
             android:requiredAccountType="string"
             android:restrictedAccountType="string"
             android:supportsRtl=["true" | "false"]
             android:taskAffinity="string"
             android:testOnly=["true" | "false"]
             android:theme="resource or theme"
             android:uiOptions=["none" | "splitActionBarWhenNarrow"]
             android:vmSafeMode=["true" | "false"] >
    . . .
</application>

   它可以包含:

<activity> 
<activity-alias> 
<service> 
<receiver> 
<provider> 
<uses-library>

• android:hardwareAccelerated
  当绘制应用的所有activities和views时,是否启用了硬件加速。
  默认值:"true": 如果minSdkVersion or targetSdkVersion大于等于14
                "false":如果minSdkVersion or targetSdkVersion小于14

• android:permission
   需要与此应用交互的客户端必须具有的权限。

• android:persistent
   标志应用是否一直运行。普通应用程序通常不应该设置为"true",此模式是为特定的系统应用程序所用。

• android:process
   所有应用组件应当在进程名由android:process指定的进程中运行。每个组件也可以指定它所运行的进程名。
   当应用中的组件第一次需要运行时,Android系统默认为为它创建一个进程,且进程名为“package name”。
   如果两个应用运行在同一个进程,则它们必须具有相同的userID和签名。

8. <activity> </activity>

<activity android:allowTaskReparenting=["true" | "false"]
          android:alwaysRetainTaskState=["true" | "false"]
          android:clearTaskOnLaunch=["true" | "false"]
          android:configChanges=["mcc", "mnc", "locale",
                                 "touchscreen", "keyboard", "keyboardHidden",
                                 "navigation", "screenLayout", "fontScale", "uiMode",
                                 "orientation", "screenSize", "smallestScreenSize"]
          android:enabled=["true" | "false"]
          android:excludeFromRecents=["true" | "false"]
          android:exported=["true" | "false"]
          android:finishOnTaskLaunch=["true" | "false"]
          android:hardwareAccelerated=["true" | "false"]
          android:icon="drawable resource"
          android:label="string resource"
          android:launchMode=["multiple" | "singleTop" |
                              "singleTask" | "singleInstance"]
          android:multiprocess=["true" | "false"]
          android:name="string"
          android:noHistory=["true" | "false"]  
          android:parentActivityName="string" 
          android:permission="string"
          android:process="string"
          android:screenOrientation=["unspecified" | "behind" |
                                     "landscape" | "portrait" |
                                     "reverseLandscape" | "reversePortrait" |
                                     "sensorLandscape" | "sensorPortrait" |
                                     "userLandscape" | "userPortrait" |
                                     "sensor" | "fullSensor" | "nosensor" |
                                     "user" | "fullUser" | "locked"]
          android:stateNotNeeded=["true" | "false"]
          android:taskAffinity="string"
          android:theme="resource or theme"
          android:uiOptions=["none" | "splitActionBarWhenNarrow"]
          android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"] >   
    . . .
</activity>
它可以包含:

<intent-filter> 
<meta-data>

       Activity活动组件(即界面控制器组件)的声明标签,Android应用中的每一个Activity都必须在AndroidManifest.xml配置文件中声明,否则系统将不识别也不执行该Activity。<activity>标签中常用的属性有:Activity对应类名android:name,对应主题android:theme,加载模式android:launchMode,键盘交互模式android:windowSoftInputMode等。

9. <activity-alias> </activity-alias>

<activity-alias android:enabled=["true" | "false"]
                android:exported=["true" | "false"]
                android:icon="drawable resource"
                android:label="string resource"
                android:name="string"
                android:permission="string"
                android:targetActivity="string" >
    . . .
</activity-alias>

它可以包含:

<intent-filter> 
<meta-data>

10. <service> </service>

<service android:enabled=["true" | "false"]
         android:exported=["true" | "false"]
         android:icon="drawable resource"
         android:isolatedProcess=["true" | "false"]
         android:label="string resource"
         android:name="string"
         android:permission="string"
         android:process="string" >
    . . .
</service>

它可以包含:

<intent-filter> 
<meta-data>












  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值