[安卓]AndroidManifest.xml文件简介及结构
1、AndroidManifest.xml文件简介:
每个应用程序在它的根目录中都必须要有一个AndroidManifest.xml(名字须精确一致)文件。这个清单把应用程序的基本信息提交给Android系统,在应用程序的代码能够运行之前,这个信息系统必须建立。以下项目是清单文件所需要完成的工作:
【注】:这个文件是需要程序员手动配置的,所以了解它的作用和结构很有必要。
- 1. 用Java包给应用程序命名。这个包名是应用程序的唯一标识;
- 2. 描述应用程序的组件---组成应用程序的Activity、Service、Broadcast Receiver以及Content Provider。它要用每个组件的实现类来命名,并向外发布对应组件功能(例如,组件所能处理的Intent消息)。这些声明会让Android系统了解应用程序中组件,以及这些组件被加载的条件。
- 3. 判断哪些进程是主应用程序组件。
- 4. 声明应用程序所必须的权限,以便能够访问被保护的API,以及能够跟其他应用程序进行交互。
- 5. 为了跟应用程序组件进行交互,还声明了其他要求有的权限。
- 6. 列出了能够提供应用程序运行时的分析和其他信息的Instrumentation类。只有在开发和测试应用程序时才在清单文件中声明这些类,在应用程序被发布之前,要删除这些类。
- 7. 声明应用程序所要求的最小的Android API级别。
- 8. 列出应用程序必须链接的外部库。
官网原文如下:
- It names the Java package for the application. The package name serves as a unique identifier for the application.
- It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which
Intentmessages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched. - It determines which processes will host application components.
- It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
- It also declares the permissions that others are required to have in order to interact with the application's components.
- It lists the
Instrumentationclasses 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. - It declares the minimum level of the Android API that the application requires.
- It lists the libraries that the application must be linked against.
1.1、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>
<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>
1.2、AndroidManifest.xml文件约定:
AndroidManifest.xml文件中的元素和属性需要遵守一些约定和规则:
1.2.1、元素:
只用<manifest>和<application>元素是必须的,而且这两个元素在文件中只能出现一次。其他元素则可以多次出现在清单中,或者根本就不出现---但是为了构建一个有意义的清单,必须要在清单中声明某些元素。如果一个元素包含了一切,它包含了其他元素(If an element contains anything at all, it contains other elements)。所有的值都是通过属性来设置的,而不是用夹在开闭元素之间的字符数据。相同级别的元素通常是没有顺序的。例如,<activity>、<provider>、<service>元素可以是任意顺序的。(<activity-alias>元素是个例外,它必须放在它所代表的<activity>元素的后面。)
1.2.2、属性:
在正式的含义中,所有的属性都是可选的,但是,为了达成目的,必须要给元素指定一些属性。对于真正的可选属性,会指定发生在特殊情况下的默认值或状态。除了<manifest>根元素的一些属性之外,其他所有属性的命名都带有android:前缀---例如,android:alwaysRetainTaskState。因为这个前缀是通用的,所以本文档在提到属性名时,通常会忽略这个前缀。
未完
2、具体元素解释:
[安卓]AndroidManifest.xml文件简介及结构的更多相关文章
- [安卓学习]AndroidManifest.xml文件内容详解
一,重要性 AndroidManifest.xml是Android应用程序中最重要的文件之一.它是Android程序的全局配置文件,是每个 android程序中必须的文件.它位于我们开发的应用程序的根 ...
- [转]AndroidManifest.xml文件详解
转自:http://www.cnblogs.com/greatverve/archive/2012/05/08/AndroidManifest-xml.html AndroidManifest.xml ...
- android基础知识13:AndroidManifest.xml文件解析
注:本文转载于:http://blog.csdn.net/xianming01/article/details/7526987 AndroidManifest.xml文件解析. 1.重要性 Andro ...
- AndroidManifest.xml文件综合详解(转)
一,重要性AndroidManifest.xml是Android应用程序中最重要的文件之一.它是Android程序的全局配置文件,是每个 android程序中必须的文件.它位于我们开发的应用程序的根目 ...
- Android之AndroidManifest.xml文件解析
转自:Android学习笔记之AndroidManifest.xml文件解析 一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文 ...
- 查看 AndroidManifest.xml文件
1.Manifest Explorer 装在Android手机中,用此apk看系统中已安装应用的AndroidManifest.xml文件: protected boolean configForPa ...
- 安卓解析XML文件
安卓解析XML文件 主要有三种方式:DOM解析.SAX解析.PULL解析 其中: DOM解析为等XMl文件全部加载后,然后根据需要解析的内容解析出所需的内容数据. SAX解析为从XML文件中执行一行, ...
- AndroidManifest.xml文件详解
本文为安全专家李洋的最新一篇专栏文章<AndroidManifest.xml文件详解>.AndroidManifest.xml是一个跟安全相关的配置文件,该配置文件是Android安全保障 ...
- Android Studio 学习 - AndroidManifest.xml文件学习
首先,今天发现了一个很牛逼的教程网站:慕课网(http://www.imooc.com/).有很多大牛发布的教学视频.值得收藏.学习. 今天主要参照陈启超老大的视频,学习了多个Activity之间的切 ...
随机推荐
- dshow,Sample Grabber 从摄像头采集
char* CCameraDS::QueryFrame() { long evCode, size = 0; #if CALLBACKMODE static double lastSampleTime ...
- vs2010配置OpenCV2.4.7详细步骤
vs2010配置opencv2.4.7 需要注意:opencv里x86的vc10对应vs2010版本,vc11对应vs2012版本,vc12对应vs2013及以上版本,若vs2013版本的软件配置时选 ...
- C\C++头文件说明
C\C++编程时候经常会遇到头文件问题而出现一系列的调试错误,下面我就简要的举例介绍一下头文件的作用,我们知道一个C\C++ 程序中开头一般都为: #include<iostream.h> ...
- phalcon: 获取参数的方法
phalcon: 获取参数的方法 一般情况下:GET/POST $this->request->get(参数); $this->request->getPost("参 ...
- SCCM 部署操作系统 ,提示权限问题,报错:0xc00000098
SCCM 部署操作系统 ,提示权限问题,报错:0xc00000098 这个问题通过查看日志,论坛搜索,博客等.下面是最终的解决方法: 1.检查所有组件是否已安装.(IIS组件等).(分发站点证书是否正 ...
- signalR的一些细节
获取根目录通过AppDomain.CurrentDomain.BaseDirectory 因为不能直接获取session ,使用的替代方案如下 private static Dictionary< ...
- linux笔记:linux常用命令-网络命令
网络命令:ping(测试网络连通性) 网络命令:ifconfig(查看和设置网卡信息) 注意:在查看网卡信息时,直接输入ifconfig命令即可. 网络命令:last(列出目前和过去登入系统的用户信息 ...
- 如何理解和熟练使用JS 中的call apply
有时候看一两个关于apply或call的小例子,感觉能够理解一点点但是下次碰到又要纠结半天才能转过弯来-而且不知道怎么应用到实际工作当中去- call 和 apply 都是为了改变某个函数运行时的 c ...
- Linux基础: 系统加载过程和运行级别含义
BIOS 有固化代码指向mbr,mbr指向grub(/boot/grub/下有很多引导配置信息),grub里可以配置多种linux内核vmlinux文件. 启动内核以后就开始加载各种驱动模块并进行系统 ...
- ACM2 递归 n分成k份
//将n 分成k份的 分法总数 #include "stdafx.h" #include"stdio.h" #include<iostream> u ...