AndroidManifest.xml文件說明--翻譯稿

自己翻譯的,感謝谷歌,感謝有道。英文水平比較差,勉強翻譯了自己看的,保留了原文,翻譯的比較爛,歡迎來噴。

The AndroidManifest.xml File
Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code. Among other things, the manifest does the following:

每個應用程序都必須有一個AndroidManifest.xml文件(名稱是固定的)在根目錄下。這個清單描述了安卓系統程序的基本信息,系統運行必須獲得這些信息才能運行此程序。除了這些,這個清單還包含如下信息:
  • 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.
  • 清單還描述了次程序的各個組件-程序包含的活動,服務,廣播接收器和內容提供者。它聲明瞭實現各個組件的類併發布了它們的能力(比如,那個Intent的消息可以被處理)。這些聲明讓安卓系統知道都有那些組件以及在什麼條件下可以激活這些組件。
  • 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.
  • 它決定了程序爲了訪問受限的API和其他程序必須擁有哪些權限。
  • 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.
  • 它列出了Instrumentation類,在程序運行時提供日至及其他信息。聲明的類僅在開發和測試過程中有效,在發佈時將被移除。
  • It declares the minimum level of the Android API that the application requires.
  • 它聲明瞭程序要求的最小安卓系統級別。
  • It lists the libraries that the application must be linked against.
  • 它聲明瞭程序所需鏈接的庫。
Structure of the Manifest File
清單文件結構


The diagram below shows the general structure of the manifest file and every element that it can contain. Each element, along with all of its attributes, is documented in full in a separate file. To view detailed information about any element, click on the element name in the diagram, in the alphabetical list of elements that follows the diagram, or on any other mention of the element name.
下圖給出了一個清單文件的通用的結構及包含的元素。每一個元素,以及它們的屬性,全部紀錄在一個獨立的文件中。要查看每一個元素的細節,請點擊下圖中的元素名稱。各元素及其他提及的元素名稱在下圖中按照字母排序。
<?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>

All the elements that can appear in the manifest file are listed below in alphabetical order. These are the only legal elements; you cannot add your own elements or attributes.
下面列出的所有元素都可以出現在清單文件中。這些元素名稱是確定的,你不能在清單中添加自己的元素或者屬性。


File Conventions
文件約定


Some conventions and rules apply generally to all elements and attributes in the manifest:
所有元素在文檔清單中普遍適用的一些約定和規則:

Elements
元素
Only the <manifest> and <application> elements are required, they each must be present and can occur only once. Most of the others can occur many times or not at all — although at least some of them must be present for the manifest to accomplish anything meaningful.
僅manifest和application元素是必須的,它們必須出現且只能出現一次。其他大部分可以出現多次或者根本不出現--儘管少數爲了清單具有意義必須出現。

If an element contains anything at all, it contains other elements. All values are set through attributes, not as character data within an element.
如果一個元素包含任何內容,及它所包含的其他元素。所有的值必須通過屬性設置,而不能通過字符數據設置。

Elements at the same level are generally not ordered. For example, <activity><provider>, and<service> elements can be intermixed in any sequence. (An <activity-alias> element is the exception to this rule: It must follow the <activity> it is an alias for.)
同一個級別的元素不要求順序,比如,<activity><provider>, 和<service> 元素可以以任何順序出現。( <activity-alias> 元素是個例外,它必須跟在它所引用的<activity> 後面。)

Attributes
屬性
In a formal sense, all attributes are optional. However, there are some that must be specified for an element to accomplish its purpose. Use the documentation as a guide. For truly optional attributes, it mentions a default value or states what happens in the absence of a specification.
正式來講所有的屬性都是可選的,不過有一些是完成編譯工作必須出現的。通過手冊文檔,對於真正可選的屬性,它描述了默認值或者一個特定情況下的處理。

Except for some attributes of the root <manifest> element, all attribute names begin with an android:prefix — for example, android:alwaysRetainTaskState. Because the prefix is universal, the documentation generally omits it when referring to attributes by name.
除了根元素 <manifest> 的一些屬性,所有屬性的名稱都使用了android:前綴--比如, android:alwaysRetainTaskState.因爲這個前綴是確定的,文檔在引用屬性時一般都忽略了它。

Declaring class names
聲明類名
Many elements correspond to Java objects, including elements for the application itself (the<application> element) and its principal components — activities (<activity>), services (<service>), broadcast receivers (<receiver>), and content providers (<provider>).
許多元素對於了Java對象,包括了程序本身的元素(<application> 元素)和它主要的組建--活動 (<activity>), 服務 (<service>), 廣播接收者 (<receiver>), 和內容提供者 (<provider>).

If you define a subclass, as you almost always would for the component classes (ActivityService,BroadcastReceiver, and ContentProvider), the subclass is declared through a name attribute. The name must include the full package designation. For example, an Service subclass might be declared as follows:
如果你定義了一個子類,因爲你幾乎總是會繼承組件類(ActivityService,BroadcastReceiver, 和 ContentProvider),這個子類通過一個name屬性聲明。這個名稱必須包含完成的包路徑。比如,一個服務子類聲明如下:

<manifest . . . ]]
    <application . . . ]]
        <service android:name="com.example.project.SecretService" . . . ]]
            . . .
        </service>
        . . .
    </application>
</manifest>

However, as a shorthand, if the first character of the string is a period, the string is appended to the application's package name (as specified by the <manifest> element's package attribute). The following assignment is the same as the one above:
不過,作爲一種簡寫方式。如果第一個字符是點號,這個字符串將被追加到應用程序的包名( <manifest> 元素的 package屬性)後面。下面的聲明與上面的聲明是等效的。

<manifest package="com.example.project" . . . ]]
    <application . . . ]]
        <service android:name=".SecretService" . . . ]]
            . . .
        </service>
        . . .
    </application>
</manifest>

When starting a component, Android creates an instance of the named subclass. If a subclass isn't specified, it creates an instance of the base class.
當啓動一個組建時,安卓創建一個子類的實例,如果子類沒有指定,它將創建一個基類的實例。//這個不太明白什麼意思。

Multiple values
多個值
If more than one value can be specified, the element is almost always repeated, rather than listing multiple values within a single element. For example, an intent filter can list several actions:
如果指定一個以上的值,該元素總是重複出現,而不是在單一元素中列出多個值。比如,一個意圖過濾器可以有多個動作。

<intent-filter . . . ]]
    <action android:name="android.intent.action.EDIT" />
    <action android:name="android.intent.action.INSERT" />
    <action android:name="android.intent.action.DELETE" />
    . . .
</intent-filter>

Resource values
資源值
Some attributes have values that can be displayed to users — for example, a label and an icon for an activity. The values of these attributes should be localized and therefore set from a resource or theme. Resource values are expressed in the following format,
有些屬性的值可以被顯示給用戶--比如,一個活動的一個標籤和一個圖標。這些屬性的值可以本地化因此通過資源設定。資源值按照如下方式表示。

@[package:]type:name

where the package name can be omitted if the resource is in the same package as the application, type is a type of resource — such as "string" or "drawable" — and name is the name that identifies the specific resource. For example:
如果資源與程序在同一個包中,可以忽略包名。type指明資源類型--比如“string”或者“drawable”--name是特定資源的標識。例如:

<activity android:icon="@drawable/smallPic" . . . ]]

Values from a theme are expressed in a similar manner, but with an initial '?' rather than '@':
主題的引用表示方法類似,不過是以“?”而不是“@”開始:

?[package:]type:name

String values
字符串值
Where an attribute value is a string, double backslashes ('\\') must be used to escape characters — for example, '\\n' for a newline or '\\uxxxx' for a Unicode character.
當屬性值是一個字符串時,雙斜槓(“\\”)是轉譯字符--比如,'\\n' 表示一個新行 或者 '\\uxxxx' 表示一個Unicode編碼字符。

File Features
文件特性


The following sections describe how some Android features are reflected in the manifest file.
下面各段聲明瞭那些安卓特性被體現在清單文件中。

Intent Filters
意圖過濾器

The core components of an application (its activities, services, and broadcast receivers) are activated by intents. An intent is a bundle of information (an Intent object) describing a desired action — including the data to be acted upon, the category of component that should perform the action, and other pertinent instructions. Android locates an appropriate component to respond to the intent, launches a new instance of the component if one is needed, and passes it the Intent object.
程序的核心組件(活動,服務和廣播接收者)都是被Intent激活的。Intent是一堆被捆綁在一起的信息(一個Intent對象)及將要發生的事情--包括預備的數據,準備執行的動作的類別,和其他相關信息。安卓定位一個合適的組建來回應這個Intent,如果需要會啓動一個新的組建實例,並將Intent對象傳遞給實例。
//這一個翻譯的不好,大家看着原文對照YY下吧。=。=!

Components advertise their capabilities — the kinds of intents they can respond to — through intent filters. Since the Android system must learn which intents a component can handle before it launches the component, intent filters are specified in the manifest as <intent-filter> elements. A component may have any number of filters, each one describing a different capability.
組件宣告它們的能力--那些種類的Intent它們可以響應--通過意圖過濾器。在一個組件啓動前,安卓系統必須瞭解那些意圖可以被它處理。意圖過濾器通過清單文件中的 <intent-filter> 指定。一個組件可以擁有多個過濾器,每一個聲明一個不同的能力。

An intent that explicitly names a target component will activate that component; the filter doesn't play a role. But an intent that doesn't specify a target by name can activate a component only if it can pass through one of the component's filters.
一個明確指定了目標組件的Intent可以激活組件,意圖過濾器這種情況下不起作用。一個Intent也可以激活沒有通過名稱明確指定的組件,但是這個Intent要符合組件的意圖過濾器。

For information on how Intent objects are tested against intent filters, see a separate document, Intents and Intent Filters.
更多的使用意圖過濾器測試意圖的信息請參考單獨的文檔, Intents and Intent Filters

Icons and Labels
圖標和標籤

A number of elements have icon and label attributes for a small icon and a text label that can be displayed to users. Some also have a description attribute for longer explanatory text that can also be shown on-screen. For example, the <permission> element has all three of these attributes, so that when the user is asked whether to grant the permission to an application that has requested it, an icon representing the permission, the name of the permission, and a description of what it entails can all be presented to the user.
一些元素都有圖標和標籤屬性,可以向用戶顯示一個小圖標和一個文本標籤。也有一個元素有一個description的屬性用來顯示一個較長的說明文本。比如,<permission> 元素有上面三種屬性,當詢問用戶是否同意這個程序的授權請求時,一個權限圖標,權限的名稱,及一個需要什麼權限的描述會呈現給用戶。

In every case, the icon and label set in a containing element become the default icon and label settings for all of the container's subelements. Thus, the icon and label set in the <application> element are the default icon and label for each of the application's components. Similarly, the icon and label set for a component — for example, an <activity> element — are the default settings for each of the component's <intent-filter>elements. If an <application> element sets a label, but an activity and its intent filter do not, the application label is treated as the label for both the activity and the intent filter.
在每種情況下,包含圖標和標籤的元素及其子元素都會使用默認的圖標及標籤設置。因此在 <application> 元素中設置了所有這個程序的組件使用的默認圖標及標籤。類似的,組件也可以設置圖標及標籤--比如,一個 <activity> 元素--默認設置由意圖過濾器指定。如果一個<application>元素設置了標籤,但是活動和它的意圖過濾器沒有設置,那麼這個程序的標籤將被用作活動和意圖的標籤。

The icon and label set for an intent filter are used to represent a component whenever the component is presented to the user as fulfilling the function advertised by the filter. For example, a filter with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings advertises an activity as one that initiates an application — that is, as one that should be displayed in the application launcher. The icon and label set in the filter are therefore the ones displayed in the launcher.
意圖過濾器的圖標和標籤是設置了給組件用的,當組件滿足意圖過濾器的條件呈現給用戶時。例如,"android.intent.action.MAIN" 和 "android.intent.category.LAUNCHER"設置的過濾器啓動一個程序--在啓動時將顯示過濾器中設置的圖標和標籤。

Permissions
權限

permission is a restriction limiting access to a part of the code or to data on the device. The limitation is imposed to protect critical data and code that could be misused to distort or damage the user experience.
權限是代碼訪問的限制或者訪問設備數據的限制。這種限制加強了重要數據的保護和防止代碼被濫用或者破壞用戶體驗。

Each permission is identified by a unique label. Often the label indicates the action that's restricted. For example, here are some permissions defined by Android:
每一個權限是一個唯一的標籤。通常這個標籤能表明行爲的限制。例如,如下一些安卓定義的權限。

android.permission.CALL_EMERGENCY_NUMBERS
android.permission.READ_OWNER_DATA
android.permission.SET_WALLPAPER
android.permission.DEVICE_POWER

A feature can be protected by at most one permission.
一個功能只能被一種權限保護。

If an application needs access to a feature protected by a permission, it must declare that it requires that permission with a <uses-permission> element in the manifest. Then, when the application is installed on the device, the installer determines whether or not to grant the requested permission by checking the authorities that signed the application's certificates and, in some cases, asking the user. If the permission is granted, the application is able to use the protected features. If not, its attempts to access those features will simply fail without any notification to the user.
如果程序需要訪問一個被權限保護的功能,它必須在清單文件中使用一個<uses-permission>元素聲明它需要的權限。然後,當程序被安裝在設備上時,安裝程序通過檢查程序的授權證書決定是否授予請求的權限,在有些情況下,會詢問用戶。如果權限被通過,程序可以使用被保護的功能。否則,程序試圖訪問功能將會直接失敗並且不會給用戶任何提示。

An application can also protect its own components (activities, services, broadcast receivers, and content providers) with permissions. It can employ any of the permissions defined by Android (listed in android.Manifest.permission) or declared by other applications. Or it can define its own. A new permission is declared with the <permission> element. For example, an activity could be protected as follows:
程序還可以通過權限保護它自己的組件(活動,服務,廣播接收者和內容提供者)。它可以採用任何權限,安卓定義的的(android.Manifest.permission種列出的)或者其他程序定義的,或者它自己定義的。使用 <permission> 元素可以聲明新的權限,例如一個活動可以通過如下方式保護自己:

<manifest . . . ]]
    <permission android:name="com.example.project.DEBIT_ACCT" . . . />
    <uses-permission android:name="com.example.project.DEBIT_ACCT" />
    . . .
    <application . . .]]
        <activity android:name="com.example.project.FreneticActivity"
                  android:permission="com.example.project.DEBIT_ACCT"
                  . . . ]]
            . . .
        </activity>
    </application>
</manifest>

Note that, in this example, the DEBIT_ACCT permission is not only declared with the <permission> element, its use is also requested with the <uses-permission> element. Its use must be requested in order for other components of the application to launch the protected activity, even though the protection is imposed by the application itself.
注意,在這個例子中,DEBIT_ACCT權限不僅僅是在 <permission>元素中聲明,它也在 <uses-permission>中做了請求聲明。這個權限必須被請求如果程序中其他組件試圖啓動這個活動,及時是程序本身提供的保護。

If, in the same example, the permission attribute was set to a permission declared elsewhere (such asandroid.permission.CALL_EMERGENCY_NUMBERS, it would not have been necessary to declare it again with a<permission> element. However, it would still have been necessary to request its use with <uses-permission>.
假如在同樣的例子中,這個權限屬性被設置爲其他地方聲明的權限(例如asandroid.permission.CALL_EMERGENCY_NUMBERS),它不用再次使用<permission>元素聲明,但是它必須使用<uses-permission>進行請求。

The <permission-tree> element declares a namespace for a group of permissions that will be defined in code. And <permission-group> defines a label for a set of permissions (both those declared in the manifest with<permission> elements and those declared elsewhere). It affects only how the permissions are grouped when presented to the user. The <permission-group> element does not specify which permissions belong to the group; it just gives the group a name. A permission is placed in the group by assigning the group name to the<permission> element's permissionGroup attribute.
<permission-tree> 元素聲明瞭代碼中定義的一組權限的名字空間。<permission-group> 定義了一個權限集合(在清單中使用<permission> 定義的或者在別的地方定義的)的標籤。它僅僅影響怎麼以分組的方式向用戶呈現權限。 <permission-group> 元素沒有定義那些權限屬於這個組,它只是用來定義一個組名稱。權限在哪個組是通過<permission> 元素的屬性 permissionGroup 定義的。

Libraries

Every application is linked against the default Android library, which includes the basic packages for building applications (with common classes such as Activity, Service, Intent, View, Button, Application, ContentProvider, and so on).
每個程序都會連接安卓的默認庫,其中包括用於構建程序的基本包(通用的類如活動,服務,意圖,視圖,按鈕,應用,內容提供者等等)。

However, some packages reside in their own libraries. If your application uses code from any of these packages, it must explicitly asked to be linked against them. The manifest must contain a separate <uses-library>element to name each of the libraries. (The library name can be found in the documentation for the package.)
當然,一些包駐留雜它們自己的庫中,如果你的程序使用了這些庫的代碼,它必須明確的要求連接它們。清單文件必須包含<uses-library>元素去聲明每一個庫。(庫的名稱可以在包中的文檔中找到。) 
發佈了56 篇原創文章 · 獲贊 11 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章