AndroidManifest.xml文件剖析

来源:互联网 发布:清华网络教学 编辑:程序博客网 时间:2024/05/01 00:01

http://hb.QQ.com  2010年04月07日17:43   IT168   

  很多网友对于Android全局配置文件AndroidManifest.xml不是很熟悉,今天我们就一起看下它完整的结构以及每个节点的作用。在我们日常的开发中都少不了下面的配置,每创建一个Activity、Service都离不开这个全局配置文件,深入的了解可以简化程序代码以及提高程序的维护性。

  在最外层包含了包名如 package=cn.android123.demo 、软件的版本号android:versionCode=1 以及 android:versionName=1.0,里面一层的application分支中将可能包含Android程序的四种对象 Activity、Service、ContentProvider以及Receiver。我们每添加上面四个类型中的任一新对象都需要在androidmanifest.xml文件中添加相应节点。

  其中Activity的属性常用的可能为android:name和android:label但我们需要了解所有的属性以帮助解决复杂的问题,完整的如下:

  android:allowTaskReparenting=[true | false]

  android:alwaysRetainTaskState=[true | false]

  android:clearTaskOnLaunch=[true | false]

  android:configChanges=[one or more of: mcc mnc locale

  touchscreen keyboard keyboardHidden

  navigation orientation fontScale]

  android:enabled=[true | false]

  android:excludeFromRecents=[true | false]

  android:exported=[true | false]

  android:finishOnTaskLaunch=[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:permission=string

  android:process=string

  android:screenOrientation=[unspecified | user | behind |

  landscape | portrait |

  sensor | nonsensor]

  android:stateNotNeeded=[true | false]

  android:taskAffinity=string

  android:theme=resource or theme

  android:windowSoftInputMode=[one or more of:stateUnspecified

  stateUnchanged stateHidden

  stateAlwaysHidden stateVisible

  stateAlwaysVisible adjustUnspecified

  adjustResize adjustPan] >

  有关AndroidManifest.xml文件的application分支我们有必要了解一些常见的属性,这里可以看到一些我们实用的选项,比如允许调试android:debuggable、任务关系android:taskAffinity,比如我们常见的方式创建一个新的任务实用标记FLAG_ACTIVITY_NEW_TASK,为程序制定一个主题,可以使用android:theme指向一个主题文件。

  平时我们创建的程序使用一些安全敏感项,会需要请求系统许可权限,这里可以使用android:permission来制定相关的许可,每个程序的service、activity、contentprovider、receiver都需要在application的节点内实现。有关完整的属性可以查看:

!--

  Code highlighting produced by Actipro CodeHighlighter(freeware)

  http://www.CodeHighlighter.com/

  -->1 <="" p="">

  2 android:allowTaskReparenting=[true | false]

  3 android:debuggable=[true | false]

  4 android:description=string resource

  5 android:enabled=[true | false]

  6 android:hasCode=[true | false]

  7 android:icon=drawable resource

  8 android:label=string resource

  9 android:manageSpaceActivity=string

  10 android:name=string

  11 android:permission=string

  12 android:persistent=[true | false]

  13 android:process=string

  14 android:taskAffinity=string

  15 android:theme=resource or theme >

  16 . . .

  17

  18

  19

  有关Androidmanifest.xml文件中的数据提供,我们来看下Provider节点中用到的定义,可以看到包含了权限控制、排序方式完整的如下:

!--

  Code highlighting produced by Actipro CodeHighlighter(freeware)

  http://www.CodeHighlighter.com/

  -->1

  2 android:enabled=[true | false]

  3 android:exported=[true | false]

  4 android:grantUriPermissions=[true | false]

  5 android:icon=drawable resource

  6 android:initOrder=integer

  7 android:label=string resource

  8 android:multiprocess=[true | false]

  9 android:name=string

  10 android:permission=string

  11 android:process=string

  12 android:readPermission=string

  13 android:syncable=[true | false]

  14 android:writePermission=string >

  15

  16

  17

  而对于服务相关定义如下:

!--

  Code highlighting produced by Actipro CodeHighlighter(freeware)

  http://www.CodeHighlighter.com/

  -->1 <="" p="">

  2 android:exported[=true | false]

  3 android:icon=drawable resource

  4 android:label=string resource

  5 android:name=string

  6 android:permission=string

  7 android:process=string >

  8

  9

  最后是Broadcast使用的Receiver定义,一般配合 和隐式处理。

!--

  Code highlighting produced by Actipro CodeHighlighter(freeware)

  http://www.CodeHighlighter.com/

  -->1 <="" p="">

  2 android:exported=[true | false]

  3 android:icon=drawable resource

  4 android:label=string resource

  5 android:name=string

  6 android:permission=string

  7 android:process=string >

  8

  9

0 0