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 Intent messages 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 Instrumentation classes 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文件简介及结构的更多相关文章

  1. [安卓学习]AndroidManifest.xml文件内容详解

    一,重要性 AndroidManifest.xml是Android应用程序中最重要的文件之一.它是Android程序的全局配置文件,是每个 android程序中必须的文件.它位于我们开发的应用程序的根 ...

  2. [转]AndroidManifest.xml文件详解

    转自:http://www.cnblogs.com/greatverve/archive/2012/05/08/AndroidManifest-xml.html AndroidManifest.xml ...

  3. android基础知识13:AndroidManifest.xml文件解析

    注:本文转载于:http://blog.csdn.net/xianming01/article/details/7526987 AndroidManifest.xml文件解析. 1.重要性 Andro ...

  4. AndroidManifest.xml文件综合详解(转)

    一,重要性AndroidManifest.xml是Android应用程序中最重要的文件之一.它是Android程序的全局配置文件,是每个 android程序中必须的文件.它位于我们开发的应用程序的根目 ...

  5. Android之AndroidManifest.xml文件解析

    转自:Android学习笔记之AndroidManifest.xml文件解析 一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文 ...

  6. 查看 AndroidManifest.xml文件

    1.Manifest Explorer 装在Android手机中,用此apk看系统中已安装应用的AndroidManifest.xml文件: protected boolean configForPa ...

  7. 安卓解析XML文件

    安卓解析XML文件 主要有三种方式:DOM解析.SAX解析.PULL解析 其中: DOM解析为等XMl文件全部加载后,然后根据需要解析的内容解析出所需的内容数据. SAX解析为从XML文件中执行一行, ...

  8. AndroidManifest.xml文件详解

    本文为安全专家李洋的最新一篇专栏文章<AndroidManifest.xml文件详解>.AndroidManifest.xml是一个跟安全相关的配置文件,该配置文件是Android安全保障 ...

  9. Android Studio 学习 - AndroidManifest.xml文件学习

    首先,今天发现了一个很牛逼的教程网站:慕课网(http://www.imooc.com/).有很多大牛发布的教学视频.值得收藏.学习. 今天主要参照陈启超老大的视频,学习了多个Activity之间的切 ...

随机推荐

  1. 如何判断一个GPS点是否在以另一个GPS点为圆心100米为半径的圆内(Java代码)

    题目乍一看,无从下手,仔细想了一下,原来只需要判断两个GPS点的直线距离是否<100米即可. Java代码如下: /** * 将两个经纬度坐标转化成距离(米) * * @param 2个GPS经 ...

  2. 图片(img标签)的onerror事件

    打开网页时提示 Stack overflow at line: 0.我做了截图如下: 经过分析,发现网页中存在类似如下的代码: <img src="pic.gif" oner ...

  3. Canu Tutorial(canu指导手册)

    链接:Canu Tutorial Canu assembles reads from PacBio RS II or Oxford Nanopore MinION instruments into u ...

  4. Java读取xml数据

    xml中的代码 <?xml version="1.0" encoding="UTF-8"?> <books id="aaa" ...

  5. Unity 5 中的全局光照技术详解(建议收藏)

    本文整理自Unity全球官方网站,原文:UNITY 5 - LIGHTING AND RENDERING (文章较长,请耐心阅读)简介全局光照,简称GI,是一个用来模拟光的互动和反弹等复杂行为的算法, ...

  6. C++从键盘输入文件结束符

            当我们使用一个istream对象作为条件时,其效果是检测流的状态.如果流是有效的,即流未遇到错误,那么检测成功.当遇到文件结束符,或遇到一个无效输入时(例如需要将输入读到一个int变量 ...

  7. location.pathname;outline:medium;undefined不能加引号

    1. location.pathname -- 返回URL的域名后的部分.例如 http://www.dreamdu.com/xhtml/ 返回/xhtml/ 2. 判断某个名称为undefined时 ...

  8. CentOS中输入yum报错:sudo: unable to execute /bin/yum: No such file or directory

    今天尝试更新了下虚拟机CentOS中的python版本后. 运行“yum”命令,就报错:“sudo: unable to execute /bin/yum: No such file or direc ...

  9. 25套用于Web UI设计的免费PSD网页元素模板

    Web 元素是任何网站相关项目都需要的,质量和良好设计的元素对于设计师来说就像宝贝一样.如果您正在为您的网站,博客,Web 应用程序或移动应用程序寻找完美设计的网页元素,那么下面这个列表会是你需要的. ...

  10. HTML5自学笔记[ 8 ]历史管理

    触发历史管理的三种方法: 跳转页面 改变hash值 pushState(在服务器环境下运行) 用hash值来触发历史管理: <!doctype html> <html lang=&q ...