Androidmanifest.xml Document Comprehensive explanation

Source: Internet
Author: User

One, the importance of Androidmanifest.xml is one of the most important files in Android applications. It is the global profile of the Android program and is the file that must be in each Android program. It is located at the root of the application we develop, and describes the global data in the package, including the components exposed in the packages (activities, services, and so on), their respective implementation classes, the various data that can be processed, and the location of the boot, and other important information.
Therefore, the file provides the necessary information about the application that the Android system needs, that is, the information that the system must have before any code for the application is run. The structure of a typical Android application is as follows:


Second, the main function It specifies the Java package for the application: the package name as a unique identifier for the application.
It describes the application components: which activity,service,broadcast receiver and content provider comprise the application. It specifies the classes that implement each component and the ability to publish them publicly (for example, which intent information they can hold). These statements make the Android system aware of what components are here and under what conditions they can be loaded.
It determines which processes will accommodate the application components.
It declares what permissions the application must have in order to access the protected portions of the API and to interact with other applications.
It also declares the license that other applications need to hold when interacting with the application.
It lists the instrumentation classes that can provide profiles and other information when the application is running. These statements are only available when the application is developed and tested, and they are removed before the application is officially released.
It declares the minimum level of Android API required by the application.
It lists the libraries that the application must link to.

Three, main structure and rules the following list shows the general structure of the manifest file and the elements it can contain. Each element, along with all its properties, is fully depicted in individual documents.

<?xml version= "1.0" encoding= "Utf-8"?>
<manifest>//root node, which describes all the contents of the package
<uses-permission/>//Request the security license you need to give your package a normal operation. A manifest can contain 0 or more of this element
<permission/>//declares a security license to restrict which programs can use the components and features in your package. A manifest can contain 0 or more of this element
<permission-tree/>
<permission-group/>
<instrumentation/>//Declares the code used to test this package or other Packages directive component. A manifest can contain 0 or more of this element
&LT;USES-SDK/>//Specifies the minimum SDK version number that is compatible with the current application
<application>//contains the root node of the application level component declaration in the package. This element can also contain global and default attributes in application, such as tags, icons, themes, necessary permissions, and so on. A manifest can contain 0 or one of this element (no extra one is allowed)
<activity>//Primary tool for interacting with users. When a user opens an application's initial page, an activity, most of the other pages used is also implemented by different activity and declared in another activity tag.
<intent-filter>//declares a intent value supported by a specified set of components
<action/>
<category/>
<data/>
<type/>
<schema/>
<authority/>
<path/>
</intent-filter>
<meta-data/>
</activity>
<activity-alias>
<intent-filter> ... </intent-filter>
<meta-data/>
</activity-alias>
<service>//service is a component that can run any time in the background
<intent-filter> ... </intent-filter>
<meta-data/>
</service>
<receiver>//intentreceiver enables your application to get data changes or actions that occur even if it is not currently running
<intent-filter> ... </intent-filter>
<meta-data/>
</receiver>
<provider>//contentprovider is a component used to manage persistent data and publish it to other applications
<grant-uri-permission/>
<meta-data/>
</provider>
<uses-library/>
<uses-configuration/>
</application>
</manifest>
Here are all the elements in alphabetical order that can appear in the manifest file. They are the only legitimate elements; You cannot add to your own elements or attributes.
<action>
<activity>
<activity-alias>
<application>
<category>
<data>
<grant-uri-permission>
<instrumentation>
<intent-filter>
<manifest>
<meta-data>
<permission>
<permission-group>
<permission-tree>
<provider>
<receiver>
<service>
<uses-configuration>
<uses-library>
<uses-permission>
<uses-sdk>
Description: The structure, elements, and attributes of the Androidmanifest.xml file can be viewed in the Android SDK documentation for detailed instructions. Before looking at these numerous elements and the attributes of the elements, you need to look at the rules for naming, structuring, and so on:
Elements: Only <manifest> and <application> are required in all elements and can only occur once. If an element contains other child elements, its value must be set through the properties of the child element. Elements at the same level, the descriptions of these elements are not sequential.
Properties: By Common sense, all properties are optional, but some properties must be set. Those properties that are truly optional, even if they do not exist, have a default value item description. Except for the root element <manifest> attribute, all other element attributes are named with the android: prefix;
Define the class name: all the element names correspond to their class names in the SDK, and if you define the class name yourself, you must include the class's packet name, and if the class is in the same packet as application, you can simply abbreviate "." ;
Majority entry: If an element has more than one numeric value, this element must be repeated to indicate that one of its properties has multiple numeric entries, and that multiple numeric items cannot be described in one attribute at a time;
Resource Item Description: When you need to reference a resource, it takes the following format: @[ Package:]type:name. For example <activity android:icon= "@drawable/icon" ... >
String value: Similar to other languages, if the character contains a character "\", then the escape character "\ \" must be used;

Four, the detailed description is worth mentioning some commonly used place:
1, almost all androidmanifest.xml (as well as many other Android XML files) contained namespace declarations in the first element xmlns:android= "http://schemas.android.com/apk /res/android ". This allows the various standard properties in Android to be used in the file, providing the data in most of the elements.
2, most manifests contain a single <application> element that defines all application-level components and attributes and can be used in the package.
3, any package that is considered a top-level application by the user and can be used by the program launcher needs to contain at least one activity component to support the main operation and the Launcher category. The action Android.intent.action.MAIN indicates that this is the entry point for the application. Category Android.intent.category.LAUNCHER Place this activity in the initiator window.
In the outermost <manifest> contains the package name such as package= "Cn.androidlover.demo", the software version number android:versioncode= "1" and android:versionname= The "1.0" attribute, while the inside layer of the <application> branch will probably contain four kinds of object Activity, Service, Content provider, and receiver of the Android program. Each of the new objects that we add to each of the four types above need to be added to the Androidmanifest.xml file, or the runtime will produce an exception. Each activity must have a <activity> tag corresponding to it, whether it is used externally or only in its own package. If an activity does not have a corresponding tag, you will not be able to run it.
An important part of this file is the intent-filters it contains. These filters describe where and when the activity started. Whenever an activity (or operating system) is to perform an action, such as opening a Web page or a contact book, it creates an intent object. It can carry some information describing what you want to do, what data you want to process, the type of data, and some other information. Android compares the information in the intent object and each application exposed Intent-filter to find the most appropriate activity to handle the data and actions specified by the caller. For more information on intent, please visit the intent Reference page.
Application Property Description:
For the application branch of the Androidmanifest.xml file we need to know some common properties, here are some of our useful options, such as allowing debugging android:debuggable, task-related android: Taskaffinity, such as our common way to create a new task utility tag Flag_activity_new_task, to develop a theme for the program, you can use Android:theme to point to a topic file. Usually we create a program that uses some security-sensitive items that will require permission to request the system, where you can use Android:permission to make relevant licenses, service, activity, content provider for each program, Receiver needs to be implemented within the application node. For full attributes, you can view:
<application android:allowclearuserdata=["true" | "False"]
Android:allowtaskreparenting=["true" | "False"]
Android:debuggable=["true" | "False"]
Android:description= "String Resource"
Android:enabled=["true" | "False"]
Android:hascode=["true" | "False"]
android:icon= "Drawable Resource"
Android:label= "String Resource"
Android:managespaceactivity= "string"
Android:name= "string"
Android:permission= "string"
Android:persistent=["true" | "False"]
Android:process= "string"
Android:taskaffinity= "string"
Android:theme= "resource or Theme" >
. . .
</application>
In addition: Activity properties commonly used may be android:name and Android:label two, but we need to understand all the properties to help solve complex problems, complete as follows:

  • Android:allowtaskreparenting=["true" | "False"]
  • Android:alwaysretaintaskstate=["true" | "False"]
  • Android:cleartaskonlaunch=["true" | "False"]
  • Android:configchanges=[one or more of: "MCC" "MNC" "locale" "Touchscreen" "Keyboard" "Keyboardhidden" "Navigation" "Orien Tation "" Fontscale "]
  • Android:enabled=["true" | "False"]
  • Android:excludefromrecents=["true" | "False"]
  • Android:exported=["true" | "False"]
  • Android:finishontasklaunch=["true" | "False"]
  • android:icon= "Drawable Resource"
  • Android:label= "String Resource"
  • android:launchmode=["multiple" | "Singletop" | "Singletask" | "SingleInstance"]
  • Android:multiprocess=["true" | "False"]
  • Android:name= "string"
  • Android:nohistory=["true" | "False"]
  • Android:permission= "string"
  • Android:process= "string"
  • android:screenorientation=["Unspecified" | "User" | "Behind" | "Landscape" | "Portrait" | "Sensor" | "Nonsensor"]
  • Android:statenotneeded=["true" | "False"]
  • Android:taskaffinity= "string"
  • Android:theme= "Resource or theme"
  • Android:windowsoftinputmode=[one or more of: "Stateunspecified" "stateunchanged" "Statehidden" "Statealwayshidden" " Statevisible "" Statealwaysvisible "" adjustunspecified "" Adjustresize "" Adjustpan "]

From the definition used in the provider node, you can see that the permissions control is included and the ordering is complete as follows:
<provider android:authorities= "List"
Android:enabled=["true" | "False"]
Android:exported=["true" | "False"]
Android:granturipermissions=["true" | "False"]
android:icon= "Drawable Resource"
Android:initorder= "Integer"
Android:label= "String Resource"
Android:multiprocess=["true" | "False"]
Android:name= "string"
Android:permission= "string"
Android:process= "string"
Android:readpermission= "string"
Android:syncable=["true" | "False"]
android:writepermission= "string" >
</provider>
The service-related definitions are as follows:
<service android:enabled=["true" | "False"]
Android:exported[= "true" | "False"]
android:icon= "Drawable Resource"
Android:label= "String Resource"
Android:name= "string"
Android:permission= "string"
Android:process= "string" >
</service>
Finally, the receiver definition used by broadcast, general mates and implicit processing.
<receiver android:enabled=["true" | "False"]
Android:exported=["true" | "False"]
android:icon= "Drawable Resource"
Android:label= "String Resource"
Android:name= "string"
Android:permission= "string"
Android:process= "string" >
</receiver>
In short, the Androidmanifest.xml file may seem complicated, but as long as we clarify the role of the elements inside, then everything becomes simple.
Finish

Androidmanifest.xml Document Comprehensive explanation (turn)

Related Article

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.