Devel/bblocks-manifest

From Android中文网

Android中文网(androidcn.net) 版权申明 : creativecommons licenses
Jump to: navigation, search

[编辑] AndroidManifest.xml 文件

AndroidManifest.xml is a required file for every application. It sits in the root folder for an application, and describes global values for your package, including the application components (activities, services, etc) that the package exposes and the implementation classes for each component, what kind of data each can handle, and where they can be launched.

AndroidManifest.xml是每一个应用都需要的文件. 位于应用根目录下, 描述了程序包的一个全局变量, 包括暴露的应用组件(activities, services等等)和为每个组件的实现类, 什么样的数据可以操作, 以及在什么地方运行.

An important aspect of this file are the intent filters that it includes. These filters describe where and when that activity can be started. When an activity (or the operating system) wants to perform an action such as open a Web page or open a contact picker screen, it creates an Intent object. This object can hold several descriptors describing what you want to do, what data you want to do it to, the type of data, and other bits of information. Android compares the information in an Intent object with the intent filter exposed by every application and finds the activity most appropriate to handle the data or action specified by the caller. More details on intents is given in the Intent reference page.

这个文件的一个重要方面(概念)是其中的intent过滤器. 这个过滤器描述了何时何种情况下让activity 启动. 当一个activity(或是操作系统)想要执行一个动作, 例如打开一个Web页或是打开一个联系人选取屏幕, 会创建一个Intent对象. 该对象包含了很多的描述信息, 描述了你想做什么操作, 你想处理什么数据, 数据的类型, 以及一些其他的重要信息. Android拿这个Intent的信息与所有应用暴露的intent过滤器比较, 找到一个最能恰当处理请求者要求的数据和action的activity. intents的更多信息在Intent页.

Besides declaring your application's Activities, Content Providers, Services, and Intent Receivers, you can also specify permissions and instrumentation (security control and testing) in AndroidManifest.xml. For a reference of the tags and their attributes, please see AndroidManifest.

另外还要声明您的应用的Activities, Content Providers, Services, 和 Intent Receivers, 你也可以在AndroidManifest.xml文件中指定权限和instrumentation(安全控制和测试). 请查看AndroidManifest, 了解这个标签和他们的属性.

A simple AndroidManifest.xml looks like this:

一个AndroidManifest.xml文件的例子:

   <?xml version="1.0" encoding="utf-8"?>
   
   <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my_domain.app.helloactivity">
   
       <application android:label="@string/app_name">
       
           <activity class=".HelloActivity">
               <intent-filter>
                   <action android:value="android.intent.action.MAIN"/>
                   <category android:value="android.intent.category.LAUNCHER"/>
               </intent-filter>
           </activity>
           
       </application>
       
   </manifest>

Some general items to note:

这里记录了一些通用特性:

  • Almost every AndroidManifest.xml (as well as many other Android XML files) will include the namespace declaration xmlns:android="http://schemas.android.com/apk/res/android" in its first element. This makes a variety of standard Android attributes available in the file, which will be used to supply most of the data for elements in that file.
  • 几乎所有的AndroidManifest.xml 文件(同其他的Android文件一样)都会包含一个命名空间的声明-xmlns:android="http://schemas.android.com/apk/res/android"-在第一个元素中. 该声明使标准Android属性在该文件中得以使用, 该属性为文件的xml元素提供了大部分数据.
  • Most manifests include a single <application> element, which defines all of the application-level components and properties that are available in the package.
  • 大多数AndroidManifest.xml 文件仅包含一个<application>元素, 该元素定了这个程序包内所有应用层面上可用的组件和属性.
  • Any package that will be presented to the user as a top-level application available from the program launcher will need to include at least one Activity component that supports the MAIN action and LAUNCHER category as shown here.
  • TODO

Here is a detailed outline of the structure of an AndroidManifest.xml file, describing all tags that are available.

下面列出了AndroidManifest.xml 这个文件详细的结构大纲, 描述了所有可用标签.

<manifest>

The root node of the file, describing the complete contents of the package. Under it you can place:
文件根节点, 描述了程序包的所有内容. 在其节点下面内可以放置:
<uses-permission>
Requests a security permission that your package must be granted in order for it to operate correctly. See the Security Model document for more information on permissions. A manifest can contain zero or more of these elements.
请求一个安全授权, 必须被授予该权限, 您的程序包才能正确的操作. 查看安全模块文档, 了解有关授权的更多信息. 一个manifest可以包含零个或多个这样的节点.
<permission>
Declares a security permission that can be used to restrict which applications can access components or features in your (or another) package. See the Security Model document for more information on permissions. A manifest can contain zero or more of these elements.
声明一个安全授权, 用来限制哪些应用可以访问您的程序包内的组件和特有机制. 查看安全模块文档, 了解有关授权的更多信息. 一个manifest可以包含零个或多个这样的节点.
<instrumentation>
Declares the code of an instrumentation component that is available to test the functionality of this or another package. See Instrumentation for more details. A manifest can contain zero or more of these elements.
TODO
<application>
Root element containing declarations of the application-level components contained in the package. This element can also include global and/or default attributes for the application, such as a label, icon, theme, required permission, etc. A manifest can contain zero or one of these elements (more than one application tag is not allowed). Under it you can place zero or more of each of the following component declarations:
描述程序包内应用级别组件的根节点. 该节点能够描述应用程序的全局(和/或)默认属性, 例如标签, 图标, 主题, 需要的授权, 等等. 一个manifest可以包含零个或一个这样的节点(多个application 节点是不允许的). 在该节点下, 可以包含零个或多个以下每个组件的声明:
<activity>
An Activity is the primary facility for an application to interact with the user. The initial screen the user sees when launching an application is an activity, and most other screens they use will be implemented as separate activities declared with additional activity tags.
Activity 是应用于用户交互的最主要机制. 当一个应用运行的时候, 用户看到的第一个屏幕就是activity, 并且, 用户所使用的其他绝大多数屏幕(界面)也会是
Note: Every Activity must have an <activity> tag in the manifest whether it is exposed to the world or intended for use only within its own package. If an Activity has no matching tag in the manifest, you won't be able to launch it.
Optionally, to support late runtime lookup of your activity, you can include one or more <intent-filter> elements to describe the actions the activity supports:
<intent-filter>
Declares a specific set of Intent values that a component supports, in the form of an IntentFilter. In addition to the various kinds of values that can be specified under this element, attributes can be given here to supply a unique label, icon, and other information for the action being described.
<action>
An Intent action that the component supports.
<category>
An Intent category that the component supports.
<type>
An Intent data MIME type that the component supports.
<scheme>
An Intent data URI scheme that the component supports.
<authority>
An Intent data URI authority that the component supports.
<path>
An Intent data URI path that the component supports.
<receiver>
An IntentReceiver allows an application to be told about changes to data or actions that happen, even if it is not currently running. As with the activity tag, you can optionally include one or more <intent-filter> elements that the receiver supports; see the activity's <intent-filter> description for more information.
一个IntentReceiver 可以让应用接收到一次数据变化和一次行为发生的通知, 甚至这个应用没有在运行也可以. 同activity 标签一样, 你可以选择包含一个或多个<intent-filter>元素; 查看activity的<intent-filter>标签描述了解更多信息.
<service>
A Service is a component that can run in the background for an arbitrary amount of time. As with the activity tag, you can optionally include one or more <intent-filter> elements that the receiver supports; see the activity's <intent-filter> description for more information.
Service 是一个在后台任意时刻都可以运行的组件. 同activity 标签一样, 你可以选择包含一个或多个<intent-filter>元素; 查看activity的<intent-filter>标签描述了解更多信息.
<provider>
A ContentProvider is a component that manages persistent data and publishes it for access by other applications.
ContentProvider组件是用来管理数据持久化及数据发布的, 发布的数据可以被其他的应用访问.
Personal tools