Androidmanifest.xml Official Introduction

Source: Internet
Author: User

  每个Android应用的根目录中都必须包含一个 AndroidManifest.xml 文件。  清单文件为 Android 系统提供有关您的应用的基本信息,系统必须获得这些信息才能运行任意应用代码。  此外,清单文件还可执行以下操作:  1,为应用的 Java 软件包命名。即:构成应用的 Activity、服务、广播接收器和内容提供程序。  2,为实现每个组件的类命名并发布其功能(例如,它们可以处理的 Intent 消息)。  3,声明应用必须具备哪些权限才能访问 API 中受保护的部分并与其他应用交互还声明其他应用与该应用组件交互所需具备的权限列出   Instrumentation 类,这些类可在应用运行期间提供分析和其他信息等。文件内容及格式如下
<?xml version= "1.0" encoding= "Utf-8"?><!--<manifest> elements are required and must exist and only occur once && except for some properties of the root <manifest> element, all property names begin with the android: prefix, for example, Android:alwaysretaintaskstate. Because the prefix is generic, this document usually ignores the property by name when it is referenced. -<manifest><!--permissions are a limitation that restricts access to data on some code or device. Restrictions are imposed to protect critical data and code that may be misused to disrupt or impair the user experience. -    <uses-permission />    <permission />    <!--<permission-tree> element is a set of rights declaration namespaces that will be defined in code. -    <permission-tree />   <!--<permission-group> defines a label for a set of permissions, including permissions that are declared in the manifest file with <permission> elements and permissions that are declared in other locations. -    <permission-group />    <instrumentation />    <uses-sdk />    <uses-configuration />      <uses-feature />      <supports-screens />      <compatible-screens />      <supports-gl-texture />  <!--<application> elements are also required and must exist and appear only once--    <application><!--elements of the same level are not sorted in order. For example,,<activity>, <provider>, <receiver>, and <service> elements can be mixed in any order. -        <activity>        All properties of the <!--component are optional. However, some properties must be assigned to an element for its purpose. -<!--If you can specify more than one value, you almost always repeat this element instead of listing multiple values within a single element. such as: <intent-filter > <action android:name= "Android.intent.action.EDIT"/> <action android:name= "a Ndroid.intent.action.INSERT "/> <action android:name=" Android.intent.action.DELETE "/> ... </intent-fi Lter>-->                <action />                <category />                <data />            </intent-filter>            <meta-data />        </activity>        <activity-alias>            <intent-filter>. . .</intent-filter>            <meta-data />        </activity-alias><!--many elements correspond to Java objects, including elements of the app itself (<application> elements) and their main components (<activity>), Services (<service>), broadcast sinks ( <receiver>) and content providers (<provider>). If you define subclasses in a way that you have almost always used for component classes (Activity, Service, Broadcastreceiver, and ContentProvider), that subclass is declared by the name attribute. The name must contain the full package name. -        <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>

——— –androidmanifest.xml File Detailed agreement ——— –

Some conventions and rules apply universally to all elements and attributes in a manifest file: elements are only<manifest>And<application>Elements are required, and they must all exist and appear only once. Most of the other elements can occur multiple times or do not appear at all, even if there must be at least some of these elements in the manifest file to accomplish any meaningful operation. If an element contains some content, it contains other elements as well. All values are set through attributes, not through character data within the element. Elements of the same level are usually in no order of precedence. For example<activity>、<provider>And<service>Elements can be mixed in any order. (<activity-alias>element does not apply to this rule: it must be followed by the name of the<activity>After. property, in a sense, all properties are optional. However, some properties must be assigned to an element for its purpose. Please use this document as a reference. For a truly optional property, it will specify the default value or what will be done if the declaration lacks a specification. In addition to the root<manifest>element, all property names begin with the android: prefix, for example, Android:alwaysretaintaskstate. Because the prefix is generic, this document usually ignores the property by name when it is referenced. Declares a class name many elements correspond to Java objects, which include elements of the application itself (<application>elements) and their main components-activity (<activity>), Services (<service>), broadcast receivers (<receiver>) and the content provider (<provider>)。 If you define subclasses in a way that you have almost always used for component classes (Activity, Service, Broadcastreceiver, and ContentProvider), that subclass is declared by the name attribute. The name must contain the full package name. For example, the Service subclass might be declared as follows:<manifest . . . >    <application . . . >        <service android:name="Com.example.project.SecretService" . . . >. . .</Service>. . .</Application></manifest>However, for simplicity, if the first character of the string is a period, the string is appended to the app's package name (as<manifest>element as specified in the Package property. The following assignments are the same as the preceding methods:<manifest package ="Com.example.project" . . . >    <application . . . >        <service android:name=". Secretservice " . . . >. . .</Service>. . .</Application></manifest>When you start a component, Android creates an instance of the named subclass. If no child class is specified, an instance of the base class is created. Multiple values If you can specify more than one value, you almost always repeat this element instead of listing multiple values within a single element. For example, the Intent filter can list multiple 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>The value of some properties of a resource value can be displayed to the user, for example, the Activity's label and icon. The values of these properties should be localized, so they need to be set through a resource or theme. The value of the resource is represented in the following format: @[package:]type:name if the resource is in the same package as the app, it can be ignored, and type is a resource type, such as a string character or picture; name is the name that identifies the specific resource. For example:<activity Android:icon="@drawable/smallpic" . . . >The values in the topic are represented in a similar way, but with the "?" Start instead of "@":? [Package:]type:name string character value if the property value is a string character, you must use a double backslash ("\ \") to escape the character. For example, use "\\n" to indicate a newline character or use "\\uxxxx" for Unicode characters. The file feature below describes how to take advantage of some Android features in the manifest file. The core component of the Intent filter application (its Activity, service, and broadcast receiver) is activated by Intent. Intent is a series of information (Intent objects) that describe the desired action, including the data to perform the action, the category of components that should perform the action, and other relevant instructions. Android will find the right component to respond to Intent, launch a new instance of the component as needed, and pass it to the Intent object. The component will advertise its functionality through the Intent filter, which is the type of Intent they can respond to. Since the Android system must understand which Intent the component can handle before starting a component, the Intent filter is specified in the manifest file as<intent-filter>Elements. A component may have any number of filters, each of which describes a different function. Explicitly naming the Intent of the target component activates the component, and the filter does not work. However, a Intent that does not specify a target by its name activates the component only if it is able to pass a filter on the component. For information about how to test Intent objects based on the Intent filter, see separate document Intent and Intent filters. Icons and labels for small icons and text labels that can be displayed to users, a number of elements have icon and label properties. In addition, some elements also have the Description property for longer descriptive text that can also be displayed on the screen. For example<permission>Element has all of these three attributes. Therefore, when the system asks the user whether to grant permission to the app, the permission icon, the permission name, and the description of the required information can be presented to the user. In either case, the icons and labels set in the containing element will be the default icon and label settings for all container child elements. Therefore, in<application>The icons and labels set in the elements are the default icons and labels for each app component. Similarly, for components (for example,<activity>Element) to set the icon and label are the components of each<intent-filter>The default setting for the element. If<application>element to set the label, but the activity and its Intent filter do not do this, the app label will be considered the tag of the activity and the Intent filter. When implementing the functionality advertised by the Intent filter, the component is represented by the icon and label set for the filter as long as the component is presented to the user. For example, a filter with "Android.intent.action.MAIN" and "Android.intent.category.LAUNCHER" settings will advertise Activity as a feature that launches an app, i.e., Advertised as a feature that should be displayed in the app launcher. As a result, icons and labels that are set in the filter are icons and labels that appear in the launcher. Permission permissions are a restriction that restricts access to data on some code or device. Restrictions are imposed to protect critical data and code that may be misused to disrupt or impair the user experience. Each of these permissions is identified by a unique label. A label usually indicates a restricted operation. For example, the following are some of the 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 privilege. If your app requires access to a rights-protected feature, you must use it in the manifest file<uses-permission>This permission is required for an element declaration application. However, after the app is installed on the device, the installer will determine whether to grant the requested permission by examining the authority that signed the application certificate and, in some cases, asking the user. If permissions are granted, the app can use protected features. Otherwise, its attempts to access these features will fail, and no notification will be sent to the user. In addition, apps can use permissions to protect their own components (Activity, services, broadcast receivers, and content providers). It can be used as defined by Android (such as Android. manifest.permission) or any permissions that are declared by other apps. Or, it can define its own permissions. New Permissions with<permission>element to declare. For example, Activity can be protected as follows:<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 passed through the<permission>element to be declared, and its use is also<uses-permission>element to request. To enable other components of your app to start a protected Activity, you must request permission to use it, even if the protection is imposed by the application itself. Also in this example, if you set the Permission property to a permission declared in a different location (for example, Android.permission.CALL_EMERGENCY_NUMBERS), you do not need to use the<permission>element is declared again. However, it is still necessary to pass<uses-permission>Request to use it.<permission-tree>Element is a set of permission declaration namespaces that will be defined in code. While<permission-group>For a set of permissions, including in the manifest file<permission>The permissions of the element declaration and the permissions declared elsewhere) define the label. It only affects how the permissions that are provided to the user are grouped.<permission-group>element does not specify which permissions belong to the group, but only provides a name for the group. by the<permission>The Permissiongroup attribute of the element assigns the group name, and the permissions are placed in the group. Libraries each app is linked to the default Android library, which includes basic packages for building apps (as well as general-purpose classes such as Activity, Services, Intent, views, buttons, apps, ContentProvider, and so on). However, some packages reside in their own libraries. If your app uses code from any of these packages, you must explicitly require that it be linked to those packages. The manifest file must contain a separate<uses-library>element to name each of these libraries. (The library name can be found in the documentation for the package.) )

Androidmanifest.xml Official Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.