Android knowledge 011 - AndroidManifest.xml

table of Contents

What AndroidManifest that?

What is the role of AndroidManifest?

. 1 <the manifest> element

1.1 xmlns:android

1.2 package

1.3 android: versionCode

1.4 android:versionName

For 1.5  <-uses Feature> element

1.5.1 android:name

1.5.2 android:required

1.5.3 android:glEsVersion

2 <file application> element

​​​​​​​2.1 android:allowBackup

​​​​​​​2.2 android:fullBackupContent

​​​​​​​2.3 android:supportsRtl

​​​​​​​2.4 android:icon

​​​​​​​2.5 android:label

​​​​​​​2.6 android:theme

​​​​​​​2.7 android:name

. 3 <Activity> element

​​​​​​​3.1 android:name

​​​​​​​3.2 android:label

​​​​​​​3.3 android:configChanges

 3.4 android:theme

3.5  <Meta-Data> element

​​​​​​​3.5.1 android:name

​​​​​​​3.5.2 android:resource

​​​​​​​3.5.3 android:value

3.6  <Intent-Filter> element

3.6.1  <Action> element

3.6.2  <category> element


 

What AndroidManifest that?

AndroidManifest official explanation is that the application manifest (manifest meaning manifest), in the root directory of each application must contain one, and the file name must be the same, namely the use of AndroidManifest.xml. This file contains the configuration information of APP, the system needs to run in accordance with the contents inside the APP code display interface.

What is the role of AndroidManifest?

Specific to detail is:

  • The Java application package name. Package name serves as a unique identifier for the application. This is our apk name, our names are usually similar to a similar "com.android.abcd" This, and the Java class name, in order to determine make it a unique value.

Think about the name of this package is still useful, for example, by am command to start an application, use is this package name /. Activity name.

  • Various components described applications, including Activity, service, content and a broadcast receiver configured to provide application programs. It also functions to release its name and implementation class for each component, for example, they may be processed Intent message. These statements inform the relevant components of the Android system and can start the information on conditions of these components.
  • The process of determining the hosted application components.
  • Application statement which must have permission to access the protected part of the API and interaction with other applications. Also stated that other applications interact with the application components required permissions have.
  • Listed Instrumentation classes that provide analysis and other information in the application is running. These statements only when the application is in development stage appears in the list will be removed prior to application release.
  • The minimum level required to declare Android API applications. The lowest level API statement. This level can be defined in build.gradle file, the field is minSdkVersion. In the case of defined AndroidManifest.xml file is relatively small.
  • List applications must be linked to the library. Lists the necessary lib library. This stuff after the 3.0 Android Studio seems to have no function, because after the 3.0 compiler is used CMakeLists.txt file, and build.gradle file to specify the library.

 

This is an example of Google's official file teapots project, we have for this document to analyze the significance of the field. Meaning field of reference is the official document .

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.sample.teapot"
          android:versionCode="1"
          android:versionName="1.0.0.1" >

  <uses-feature android:glEsVersion="0x00020000"></uses-feature>

  <application
      android:allowBackup="false"
      android:fullBackupContent="false"
      android:supportsRtl="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme"
      android:name="com.sample.teapot.TeapotApplication"
      >

    <!-- Our activity is the built-in NativeActivity framework class.
         This will take care of integrating with our NDK code. -->
    <activity android:name="com.sample.teapot.TeapotNativeActivity"
              android:label="@string/app_name"
              android:configChanges="orientation|keyboardHidden">
      <!-- Tell NativeActivity the name of our .so -->
      <meta-data android:name="android.app.lib_name"
                 android:value="TeapotNativeActivity" />
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
</manifest>

1 <manifest> element

First, all the xml must contain <manifest> element. This is the root of the file. It must contain <application> element, and indicates xmlns: android and package attributes.

<Manifest> element attributes, see follow:

1.1 xmlns:android

This attribute defines the Android namespace. It must be set to " http://schemas.android.com/apk/res/android ." Do not manually modify.

1.2 package

This is a complete Java language-style package name. Package name from the English alphabet (uppercase or lowercase), numbers, and underscores. Each individual's name must begin with a letter.

APK's time to build, build system uses this property to do two things:

  • 1, with the class name as generated R.java namespace (for resource access of APP)
    , such as: package is provided com.sample.teapot, then the generated class R is: com.sample.teapot.R
  • 2, is used to generate the full class name defined in the manifest file class. Such package is provided com.sample.teapot, and activity element is declared as <activity android: name = ". MainActivity">, the full name of the class is com.sample.teapot.MainActivity.

Package name also represents a unique application ID, used to publish applications. However, we should pay attention to is this: In the last step APK build process, package name will be replaced by build.gradle file applicationId property. If the two attribute values the same, then everything is all right, if not the same, then beware.

1.3  android: versionCode

Internal version number. Used to indicate which version of the update. This number will not be displayed to the user. Displayed to the user is versionName. This number must be an integer. Can not use hexadecimal, that does not accept the "0x1" this parameter

​​​​​​​1.4 android:versionName

The version number is displayed to the user to see.

For 1.5  <-uses Feature> element

<Manifest> element in the elements, Google Play use this element's value will be applied non-compliant device applications that require filtering.

The role of this thing is to APP relies on hardware or software conditions tell others. It describes the function of APP which may vary with the device.

When use is to be noted, each function must be specified in a separate <uses-feature> element, if a plurality of functions, a plurality of <uses-feture> element. Such as requiring device also has Bluetooth and camera features:

<uses-feature android:name="android.hardware.bluetooth" />

<uses-feature android:name="android.hardware.camera" />

 

​​​​​​​1.5.1 android:name

<Uses-feature> attribute, which specifies the use of hardware or software features of APP as a string.

​​​​​​​1.5.2 android:required

If this attribute is true it expressed the need for this functionality otherwise the application will not work, if the representation is false application will use this feature when necessary, but if you do not have this function application can work.

​​​​​​​1.5.3 android:glEsVersion

Opengl ES version specified in the application need. High 16 represents the major version number, the lower 16 bits represent the minor version number. For example, if it is to version 3.2, it is 0x00030002. If you define multiple glEsVersion, the application will automatically enable the highest setting.


2 <application> element

This element describes the configuration application. This is an essential element that contains a lot of components to describe the application of sub-elements, its attributes affect all sub-components. Many of the properties (e.g. icon, label, permission, process, taskAffinity and its allowTaskReparenting) are set to default values.

​​​​​​​2.1 android:allowBackup

<Application> attribute. Indicates whether to allow APP was added to restore the backup structure. If set to false, then the application will not restore the backup. The default value is true.

​​​​​​​2.2 android:fullBackupContent

This attribute points to an xml file that contains the rules for making a full backup automatic backup. These rules define which files to back up. This attribute is an optional attribute. By default, automatic file backup contains most of the app.

​​​​​​​2.3 android:supportsRtl

Declare your APP supports RTL (Right To Left) layout. If set to true, and is arranged to targetSdkVersion 17 or higher. Many RTL API will fire was set, so that your application can display the RTL layout. If set to false or targetSdkVersion 16 or less is provided. What RTL API will not work.

The default value of this attribute is false.

​​​​​​​2.4 android:icon

APP icons and the default icon of each component. You can customize the icons in the group price. This property must be set to a reference to a drawable resource, the resource must contain pictures. The system does not set a default icon. For example mipmap / ic_launcher cited is the following resources

 

 

​​​​​​​2.5 android:label

A user-readable label, the label and the default for all components. Subassemblies can define your own label with their label property, if not defined, then use the tag.

Tag must be set to a string resource references. So that they can be located and other things, like, for example, @ string / app_name. Of course, in order to facilitate the development, you can define a raw string.

​​​​​​​2.6 android:theme

This attribute defines the theme used by the application, it is a pointer to the style resource references. Each activity can also use their own theme attribute set their own theme.

​​​​​​​2.7 android:name

Full name Application subclass. It includes a front path. For example com.sample.teapot.TeapotApplication. When the application starts, an instance of this class is first created. This attribute is optional, most APP do not need this property. In the absence of this attribute, Android will start an instance of the Application class.


3 <activity> element

This element declares a realization Activity (Activity Subclass) Application of the visual interface. This is the <application> element in the necessary child elements. All Activity must be represented by a manifest file <activity> element. Activity is not there any statement is not visible to the system, and will never be executed.

​​​​​​​3.1 android:name

Activity name of the class, is a subclass of the Activity class. This attribute is the fully qualified class name, e.g. com.sample.teapot.TeapotNativeActivity. For convenience, if the first character is a point ( '.'), You need to add the package name <manifest> elements. Once published application, you should not change the name.

There is no default value, you must specify the name.

​​​​​​​3.2 android:label

Activity tag, a user can be read. The label will appear on the screen when the Activity activated. If not set, a label property <application> of. Properties and requirements set <application> are the same.

​​​​​​​3.3 android:configChanges

Activity lists the discretion message configuration changes. When configuration changes occur at run time, it closes Activity then restart the default, but the use of the property declarations configuration prevents Activity restart. Activity but will keep running, and the system will call its onConfigurationChanged () method.

Note : Avoid using this property, and should only be used in case of a last resort. For more information about how to restart properly handle configuration changes caused, please read the changing process is running .

This item properties you can set many commonly used items listed here:

  • orientation
    of the screen at ease ah changes, such as the user rotates the device
  • keyboardHidden
    keyboard accessibility has changed, such as the user shows the hardware keyboard
  • android: launchMode
    instructions on how to start the Activity. There are four types of command:
    "Standard"
    "singleTop"
    "singleTask"
    "singleInstance"
    by default standard. These modes are divided into two categories: "standard" and "singleTop" is a class. Activity of the pattern may be instantiated multiple times. Examples may be of any task, and may be located anywhere in the stack Activity. "singleTask" and "singleInstance" is a class. This mode can only start the task, they are always at the root of the Activity stack. In addition, the device can only keep one Activity instance.
    After the set singleTask, the system creates Activity Intent to transfer it in the root location of the new task. If there is already an Activity instance, the system will pass the instance onNewIntent call () method to which the transfer Intent instead of creating a new Activity instance.
  •  

 3.4 android:theme

To set a theme format, and <application> is similar in theme.

3.5  <Meta-Data> element

Specify additional data item, the data item is a name-value pairs, is provided to the parent component. These data will form a Bundle object may be used by PackageItemInfo.metaData field. Although you can use multiple <meta-data> element tags, but such use is not recommended. If there are a plurality of data items to be specified, is recommended practice: The combined data items into a plurality of resources, then a <meta-data> included.

This element has three attributes:

​​​​​​​3.5.1 android:name

Data item name, which is a unique value.

​​​​​​​3.5.2 android:resource

A reference resource.

​​​​​​​3.5.3 android:value

The value of the data item.

3.6  <Intent-Filter> element

This activity may start to indicate what kind of intent (intent). This element has several sub-element can contain. We first introduce the two encountered:

3.6.1  <Action> element

Indicate what action activity as a start, android.intent.action.MAIN shown as the main activity starts.

3.6.2  <category> element

This is an additional category information action elements, android.intent.category.LAUNCHER indicates that the activity for the current application Activity highest priority.



 

 



 

Published 112 original articles · won praise 3 · Views 9706

Guess you like

Origin blog.csdn.net/yush34/article/details/104893234
011