Androidmanifest. xml file

Source: Internet
Author: User
ArticleDirectory
    • I. Importance
    • Ii. Main Functions
    • Iii. Main structures and rules
    • Iv. Details
I. Importance

Androidmanifest. XML is an android application.ProgramOne of the most important files. It is the global configuration file of the android program.
Required files in the android program. It is located in the root directory of the developed application and describes global data in the package, including components exposed in the package.
(Activities, services, and so on), as well as their respective implementation classes, various data that can be processed and startup locations, and other important information.
Therefore, the file provides the required information about the application required by the Android system, that is, anyCodeInformation required by the system before running. Shows the structure of a typical Android Application:

Ii. Main Functions

It specifies the Java package of the application: the package name is a unique identifier of the application.

It describes the application components: the activities, services, broadcast referers, and content of the application.
Provider. It specifies the classes for each component and the ability to publish them publicly (for example, the intent information they can hold ). These declarations enable the Android system to know this
What components are available and under which conditions they can be loaded.

It determines which processes will accommodate application components.

It declares the licenses required for the application to access the protected part of the API and 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 and provides the profile and other information when the application is running. These declarations are provided only when the application is being developed and tested; they will be removed before the application is officially released.

It declares the minimum level of Android APIs required by the application.

It lists the libraries that must be linked to the application.

Iii. Main structures and rules

The following list shows the common structure of the manifest file and its elements. Each element, along with all its attributes, is fully depicted in each individual document.

<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest> // The root node that describes all contents of the package.
<Uses-Permission/> // request the Security license required for normal operation of your package. A manifest can contain zero or more elements.
<Permission/> // declares a security license to restrict which programs can use the components and functions in your package. A manifest can contain zero or more elements.
<Permission-tree/>
<Permission-group/>
<Instrumentation/> // declare the code used to test the package or other package instruction components. A manifest can contain zero or more elements.
<Uses-SDK/> // specifies the minimum SDK version number compatible with the current application.

<Application>
// Contains the root node declared by the application-level component in the package. This element can also contain global and default properties in the application, such as labels, icons, and
Question, necessary permissions, and so on. One manifest can contain zero or one such element (no additional one is allowed)
<Activity> // the main tool used to interact with users. When a user opens an initial page of an application, most of the other pages used are implemented by different activities and declared in another activity tag.
<Intent-filter> // declares the intent values supported by a specified group of parts.
<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 at any time in the background.
<Intent-filter>... </intent-filter>
<Meta-data/>
</Service>
<Receiver> // intentreceiver allows your application to obtain data changes or operations, even if it is not currently running
<Intent-filter>... </intent-filter>
<Meta-data/>
</Cycler>
<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>

The following are all the elements that can appear in the manifest file alphabetically. They are the only valid elements. You cannot add 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>
<Cycler>
<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. Before looking at these elements and their attributes, you must first understand the naming and structure rules of these elements:
Element: Only <manifest> and <Application> of all elements are required and can only appear once. If an element contains other child elements, its value must be set through the attributes of the child element. Elements at the same level have no order.
Attribute: in common sense, all attributes are optional, but some attributes must be set. The optional attributes have default value descriptions even if they do not exist. Except for the root element <manifest> attribute, the names of all other element attributes are prefixed with Android;
Define Class Name: All element names correspond to their class names in the SDK. If you define a class name, it must contain the class data packet name. If the class is in the same data packet as the application, it can be abbreviated as ". ";
Multiple value items: if an element has more than one value, the element must be repeated to indicate that an attribute has multiple value items, multiple numeric values cannot be described in one attribute at a time;
Resource Description: When a resource needs to be referenced, the format is as follows :@[Package:]Type:Name.For example, <activity Android: icon = "@ drawable/icon"...>
String Value: similar to other languages. If the character contains the character "\", the escape character "\" must be used.

Iv. Details

It is worth mentioning some common features:
1. Almost all androidmanifest. XML (and many other android XML files) are stored in the first element.
Contains the namespace declaration xmlns: Android = "http://schemas.android.com/apk/res/android ". This
This allows various standard attributes in Android to be used in files and provides data in most elements.
2. Most manifests contain a single <Application> element, which defines all application-level components and attributes and can be used in a package.
3,
Any package that is considered as a top-level application and can be used by the program initiator must contain at least one activity component to support the main operation and launcher type.
Action Android. Intent. Action. Main indicates that this is the entry point of the application. Category
Android. Intent. Category. launcher places the activity in the starter window.

The <manifest> on the outermost layer contains the package name such as package = "cn. androidlover. Demo" and the software version number.
Android: versioncode = "1" and
Android: versionname = "1.0", which may contain
Four objects: Activity, service, and content
Provider and consumer er. Each time we add any of the above four types of new objects, we need to add corresponding nodes to the androidmanifest. xml file. No
Then, an exception occurs during running. Each activity must have a <activity> tag, whether used externally or only for its own package.
. If an activity has no corresponding tag, you cannot run it.

An important part of this file is its intent-filters. These filters describe the start position and time of the activity. Every time
Activity (or the operating system) needs to perform an operation. For example, when a webpage or contact book is opened, it creates an intent object. It can carry some information to describe what you want to do.
What data is processed, the data type, and some other information. Android compares the intent object with the intent-filter exposed by each application.
To find the most suitable activity to process the data and operations specified by the caller. For more information about intent, visit the intent reference page.

Application attributes:

For the application branch of the androidmanifest. xml file, we need to know some common attributes. here we can see some practical options, such
For example, Android: debuggable and task relationship Android: taskaffinity can be debugged. For example, we often create a new task utility tag.
Flag_activity_new_task: Creates a topic for the program. You can use Android: theme to point to a topic file. The programs we create usually use some
For security-sensitive items, You need to request system permission. Here, you can use Android: Permission to create related permissions,
Activity, content provider, and consumer er must be implemented in the application node. You can view the complete attributes:

1 <application Android: allowclearuserdata = ["true" | "false"]
2 Android: allowtaskreparenting = ["true" | "false"]
3 Android: debuggable = ["true" | "false"]
4 Android: Description = "string resource"
5 Android: enabled = ["true" | "false"]
6 Android: hascode = ["true" | "false"]
7 Android: icon = "drawable resource"
8 Android: Label = "string resource"
9 Android: managespaceactivity = "string"
10 Android: Name = "string"
11 Android: Permission = "string"
12 Android: Persistent = ["true" | "false"]
13 Android: Process = "string"
14 Android: taskaffinity = "string"
15 Android: theme = "resource or theme">
16...
17 </Application>

In addition, the attributes of an activity may be Android: Name and Android: label, but we need to understand all the attributes to help solve complicated problems. The complete attributes are 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" "orientation"
    "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 definitions used in the provider node, we can see that permission control and sorting are complete as follows:

1 <provider Android: Authorities = "list"
2 Android: enabled = ["true" | "false"]
3 Android: exported = ["true" | "false"]
4 Android: granturipermissions = ["true" | "false"]
5 Android: icon = "drawable resource"
6 Android: initorder = "integer"
7 Android: Label = "string resource"
8 Android: Multiprocess = ["true" | "false"]
9 Android: Name = "string"
10 Android: Permission = "string"
11 Android: Process = "string"
12 Android: readpermission = "string"
13 Android: syncable = ["true" | "false"]
14 Android: writepermission = "string">
15 </provider>

Services are defined as follows:

1 <service android: enabled = ["true" | "false"]
2 Android: exported [= "true" | "false"]
3 Android: icon = "drawable resource"
4 Android: Label = "string resource"
5 Android: Name = "string"
6 Android: Permission = "string"
7 Android: Process = "string">
8 </service>

At last, it is the definition of the receiver used by broadcast, which is generally used together with and implicitly.

1 <Cycler Android: enabled = ["true" | "false"]
2 Android: exported = ["true" | "false"]
3 Android: icon = "drawable resource"
4 Android: Label = "string resource"
5 Android: Name = "string"
6 Android: Permission = "string"
7 Android: Process = "string">
8 </Cycler>

In short, although the androidmanifest. xml file looks complicated, everything becomes simple as long as we clarify the role of each element in it.

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.