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. JavaScript:引用js文件时的编码格式问题

    JavaScript:引用js文件时的编码格式问题 如果js文件的编码格式是utf-8,并且含有中文,那么按照正常的方法引用,就会出现乱码的情况. 方法/步骤   如果js文件的编码格式是utf-8, ...

  2. javascript算术运算符详解

    算术运算符 +.-.*./.%.++.-- ++.--分为前缀形式和后缀形式 前缀形式先加减1在执行 后缀形式先执行再加减1 注意 +号用来连接两个字符串 只要+连接的操作数中有一个是字符串型,JS就 ...

  3. java 内部类2(成员内部类)

    成员内部类: 特点:在其所在的外部类,的成员函数中,的类. 难点:看注释(涉及到jvm) /*test()执行完毕时,x2从内存中消失,inner的声明周,比x2长,inner还在访问,给人的感觉好像 ...

  4. mysql5.7主从复制

    1.简介 1.1主从复制 是指建立一个和主数据库完全一样的数据库环境,称为从数据库:主数据库一般是实时的业务数据库,从数据库的作用和使用场合一般有几个: 一是作为后备数据库,主数据库服务器故障后,可切 ...

  5. DI 之 3.4 Bean的作用域(捌)

    3.4  Bean的作用域 什么是作用域呢?即"scope",在面向对象程序设计中一般指对象或变量之间的可见范围.而在Spring容器中是指其创建的Bean对象相对于其他Bean对 ...

  6. CentOS怎样查看系统信息

    一.查看系统版本和核心版本 1 登陆CentOS,启动终端. 2 登陆root帐户,输入 cat  /etc/redhat-release,即可显示系统版本. 3 输入 uname  -r ,可以查询 ...

  7. WLAN历史概述-01

    无线网络介绍 无线网络的初步应用,可以追朔到第二次世界大战期间,当时美国陆军采用无线电信号做资料的传输.他们研发出了一套无线电传输科技,并且采用相当高强度的加密技术,得到美军和盟军的广泛使用.他们也许 ...

  8. HTML5自学笔记[ 3 ]表单验证反馈

    表单控件对象的validity对象可以设置或返回相关的验证信息(在invalid事件处理中获取validity对象): 属性valid:为true所有验证通过,为False至少有一种验证失败. 属性v ...

  9. !important css样式

    重要性 我们在做网页代码的时,有些特殊的情况需要为某些样式设置具有最高权值,怎么办?这时候我们可以使用!important来解决. 如下代码: p{color:red!important;} p{co ...

  10. Java多线程-新特性-线程池

    Sun在Java5中,对Java线程的类库做了大量的扩展,其中线程池就是Java5的新特征之一,除了线程池之外,还有很多多线程相关的内容,为多线程的编程带来了极大便利.为了编写高效稳定可靠的多线程程序 ...