about AndroidManifest.xml Analysis and explanation

Time:2020-6-2

1、 About AndroidManifest.xml

AndroidManifest.xml The manifest file is a necessary file in every Android program. It is a global description file of the entire Android program. In addition to declaring activities, content providers, services, and intent receivers in the program, it can also specify the name of the application, the icon used, the components included, and permissions and instrumentation (security control and testing).

2、 List file analysis in Hello World Project


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package\="com.example.wgh.helloworld">

    <application
        android:allowBackup\="true" android:icon\="@mipmap/ic\_launcher" android:label\="@string/app\_name" android:supportsRtl\="true" android:theme\="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Explanation of each node (from top to bottom):

  • xmlns:android:Define Android namespace, so that all kinds of standard attributes in Android can be used in files, providing data in most elements.
  • package:Specifies the package name of the main java package in this application, which is also the default name of an application process.
  • application:One AndroidManifest.xml It must contain an application tag, which declares the components of each application and their properties (such as icon, label, permission, etc.).
  • allowBackup:When the allowbackup flag is true, users can backup and restore application data through ADB backup and ADB restore, which may bring some security risks.
  • icon:This is very simple. It is to declare the icon of the whole app. The pictures are usually placed in the drawable folder.
  • label:Declare the name of the entire app. String constants are usually placed in the values folder strings.xml Inside.
  • supportsRtl:Support the layout from right to left (normal layout in the mirror to see the left and right alignment).
  • theme:It is a resource style. It defines a default theme style for all activities. Of course, you can also set it in your own theme, which is similar to style.
  • activity:Define a component activity in app.
  • name:The name of the activity.
  • intent-filter:Broadcast filter, which will be discussed later.
  • <action android:name:Specify the program entry activity, which is mainactivity.
  • <category android:name:Specifies the environment in which the current action is executed. Category here_ Launcher determines whether the application appears in the program list.
  • The rest:The end node corresponding to each start node.

3、 General structure of manifest file and detailed introduction of each node

General list file structure:


<?xmlversion="1.0"encoding="utf-8"?>

<manifest>

    <application>

        <activity>

           <intent-filter>

            <action/>

            <category/>

           </intent-filter>

        </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/>

        </provider>

        <uses-library/>

    </application>

    <uses-permission/>

    <permission/>

    <permission-tree/>

    <permission-group/>

    <instrumentation/>

    <uses-sdk/>

    <uses-configuration/> 

    <uses-feature/> 

    <supports-screens/>

</manifest>

Detailed explanation of each node:

1、<Manifest>


<manifest  xmlns:android="http://schemas.android.com/apk/res/android"
    package\="com.woody.test" android:sharedUserId\="string" android:sharedUserLabel\="string resource" android:versionCode\="integer" android:versionName\="string" android:installLocation\=\["auto" | "internalOnly" | "preferExternal"\] >
</manifest>

  • xmlns:android

Define Android namespace, generally http://schemas.android.com/apk/res/android In this way, various standard attributes in Android can be used in files, providing data in most elements.

  • package

Specifies the package name of the main java package in this application, which is also the default name of an application process.

  • sharedUserId

Indicates data permission. By default, Android assigns a unique user ID to each APK, so different apks are forbidden to access shared data by default. To share data, the first method is to use the sharepreference method, and the second method is to use the shareduserid. Set the shareduserid of different apks to the same, and then the apks can share data with each other.

  • sharedUserLabel

A shared user name is meaningful only when the shareduserid property is set.

  • versionCode

It is used to identify the version (upgrade) of the device program. It must be an integer value, which represents how many times the app has been updated. For example, the first version is generally 1, and then the version to be updated is set to 2, 3, etc.

  • versionName

This name is for the user to see. You can set your app version number to version 1.1, and later update versions to version 1.2, 2.0, etc.

  • installLocation

The installation parameter is a new feature in Android 2.2. Installlocation has three values to choose from: internalonly, auto, preferexternal

  • Select preferexternal
    The system will give priority to installing APK on SD card (of course, the end user can choose internal ROM storage, and if SD storage is full, it will also be installed on internal storage).
  • Select Auto
    The system will adapt itself to the storage space.
  • Select internalonly
    Must be installed internally to run.

Note: it is better to install the app that needs background monitoring inside, and some larger game apps on SD card. The default is to install the app internally. If you install the app on the SD card, you must first set the level to 8 and configure it android:installLocation The attribute of this parameter is preferexternal

2、<Application>


<application  android:allowClearUserData=\["true" | "false"\]
    android:allowTaskReparenting\=\["true" | "false"\]
    android:backupAgent\="string" android:debuggable\=\["true" | "false"\]
    android:description\="string resource" android:enabled\=\["true" | "false"\]
    android:hasCode\=\["true" | "false"\]
    android:icon\="drawable resource" android:killAfterRestore\=\["true" | "false"\]
    android:label\="string resource" android:manageSpaceActivity\="string" android:name\="string" android:permission\="string" android:persistent\=\["true" | "false"\]
    android:process\="string" android:restoreAnyVersion\=\["true" | "false"\]
    android:taskAffinity\="string" android:theme\="resource or theme" >
</application>
  • android:allowClearUserData(‘true’ or ‘false’)

Whether users can choose to clear data by themselves is true by default. The program manager contains a choice to allow users to clear data. When it is true, users can clean user data by themselves, and vice versa.

  • android:allowTaskReparenting(‘true’ or ‘false’)

Whether to allow activity to change subordinate tasks, such as switching from SMS tasks to browser tasks.

  • android:backupAgent

This is also a new feature in Android 2.2. To set the backup of the app, the property value should be a complete class name, such as com.project.TestCase , this property has no default value, and the class name must be specified (that is, a backup tool, the operation of backing up data to the cloud).

  • android:debuggable

This can be seen literally. When it is set to true, it means that the app can be debugged on the phone. By default, it is false. When debugging the app under false, the following error will be reported:
Device XXX requires that applications explicitely declare themselves as debuggable in their manifest.
Application XXX does not have the attribute ‘debuggable’ set to TRUE in its manifest and cannot be debugged.

  • android:description / android:label

These two properties are provided for the license. They are string resources. When the user goes to the license list( android:label )Or details of a license( android:description )These string resources can be displayed to the user.
The label should be as brief as possible, just telling the user what function the license is protecting. Description can be used to specifically describe what the program that obtains the permission can do, in fact, let users know what the program can do if they agree to obtain the permission. We usually use two sentences to describe the license, the first sentence describes the license, and the second sentence warns the user that if the permission is approved, something bad may happen.

  • android:enabled

If it is true, the enabled attribute of each component determines whether that component can be enabled. If it is false, it overrides the value specified by the component, and all components are disabled.

  • android:hasCode(‘true’ or ‘false’)

Indicates whether the app contains any code. It is true by default. If it is false, the system will not try to load any app code when running components. An application itself will not contain any code unless it has built-in component classes.
For example, the activity class uses the aliasactivity class, which is a rare phenomenon (in Android 2.3, you can use standard C to develop applications, and in Android 2.3, you can use the androidManifest.xml Set this property to false, because the app itself no longer contains any Java code.)

  • android:icon

This is very simple. It is to declare the icon of the whole app. The pictures are usually placed in the drawable folder

  • android:killAfterRestore

This property refers to whether the application is terminated after a complete system recovery operation. Recovery of a single application does not cause the application to terminate. A complete system recovery operation generally occurs only once when the phone is first installed. Third party applications usually do not need to use this property. The default value of this property is true, which means that during a complete system recovery, the application will be terminated after it finishes processing its data.

  • android:manageSpaceActivity

If you want to manage your own data catalog, you can use the android:manageSpaceActivity Property to control, instead of clearing all files in / data / data / package name / by default. Of course, we can also extend it, such as clearing the data on the SD card. If we have root permission, we can also use it as garbage disposal.

  • android:name

The full name of the application subclass implemented for the application. When the application process starts, the class is instantiated before all application components. If the class (such as Android main class) is under the declared package, it can be declared directly, but if the class is a subpackage under the package, it must be declared as full path or android:name= “Package name. Subpackage name. Android main”.

  • android:permission

Setting the license name, if defined on < Application >, is a convenient way to set the license for all components of the application. Of course, it is covered by the license name set by each component.

  • android:presistent

Whether the application should keep running at any time is false by default, because the application should not set this identifier generally, and the persistence mode should only be set to some system applications is meaningful.

  • android:process

The process name of the application. Its default value is the package name set in the < manifest > element. Of course, each component can override the default value by setting this attribute. If you want two applications to share a process, you can set their android:process Same, but only if they share a user ID and are given the same certificate.

  • android:restoreAnyVersion

It is also a new feature of Android 2.2, which is used to indicate whether the application is ready to try to recover all backups, even if the backup is a newer version than the current device, and the default is false.

  • android:taskAffinity

Activities with the same affinity belong to the same task in theory. The default affinity name of the application is the package name set in the < manifest > element.

  • android:theme

It is a resource style. It defines a default theme style for all activities. Of course, you can also set it in your own theme, which is similar to style.

3、<Activity>


<activity android:allowTaskReparenting=\["true" | "false"\]
    android:alwaysRetainTaskState\=\["true" | "false"\]
    android:clearTaskOnLaunch\=\["true" | "false"\]
    android:configChanges\=\["mcc", "mnc", "locale", "touchscreen", "keyboard", "keyboardHidden", "navigation", "orientation", "screenLayout", "fontScale", "uiMode"\]
    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" | "nosensor"\]
    android:stateNotNeeded\=\["true" | "false"\]
    android:taskAffinity\="string" android:theme\="resource or theme" android:windowSoftInputMode\=\["stateUnspecified", "stateUnchanged", "stateHidden", "stateAlwaysHidden", "stateVisible", "stateAlwaysVisible", "adjustUnspecified", "adjustResize", "adjustPan"\] </activity>

  • android:alwaysRetainTaskState

Whether to keep the status unchanged, for example, switch back to home and open it again. The activity is in the final state.
For example, if a browser has many states (when multiple tabs are opened) and the user does not want to lose these States, this property can be set to true.

  • android:clearTaskOnLaunch

For example, P is an activity, q is an activity triggered by P, and then return to home, restart P, and check whether q is displayed.

  • android:configChanges

Whether to call the onconfigurationchanged() method when the configuration list is modified.
For example, “local | navigation | orientation”, which is mainly used to see the direction change of mobile phone. When Android phones rotate, layout will be rearranged. How to do this? Under normal circumstances, if the mobile phone rotates, the current activity will be killed, and then the activity will be reloaded according to the direction, starting from oncreate; if you set this option, after the mobile phone rotates, the current activity will call the onconfigurationchanged() method instead of the oncreate() method.

  • android:excludeFromRecents

Whether it can be displayed in the recently opened activity list is false by default.

  • android:finishOnTaskLaunch

When the user restarts the task, whether to close the opened activity is false by default.
If this property and allowtaskrepresenting are both true, then this property is trump card, the affinity of activity will be ignored, and the activity has been destroyed instead of re parent.

  • android:launchMode

In multi activity development, it may be an activity jump between its own applications, or a reusable activity with other applications. You may want to jump to an original activity instance instead of producing a large number of duplicate activities. This requires that a specific load mode be configured for the activity, rather than using the default load mode.

  • android:multiprocess

Whether to allow multiple processes is false by default.

  • android:noHistory

When the user leaves the activity and it is no longer visible on the screen, whether the activity clears and ends from the activity stack is false by default, and the activity will not leave a history trace.

  • android:screenOrientation

Activity display mode, default is unspecified: display direction is automatically determined by the system.
Landscape: horizontal screen mode, width ratio is large;
Portrait: vertical screen mode, the height is larger than the width;
User mode: the user’s current preferred direction;
Behind mode: consistent with the direction of the activity below the activity (in the activity stack);
Sensor mode: determined by physical sensors;
No sensor mode: ignore the physical sensor, so it will not change as the user rotates the device.

  • android:stateNotNeeded

Whether to save the status when the activity is destroyed or successfully restarted.

  • android:windowSoftInputMode

The interaction mode of activity main window and soft keyboard can be used to avoid the problem of input method panel occlusion, a new feature after Android 1.5.
This attribute can affect two things:
1. When there is focus, is the soft keyboard hidden or displayed
2. Reduce the size of the active main window to make room for the soft keyboard
Meaning of each value:

  • State unspecified: the state of the soft keyboard is not specified, and the system will select an appropriate state or subject dependent setting
  • State unchanged: when this activity appears, the soft keyboard will remain in the state of the previous activity, whether hidden or displayed
  • State hidden: when the user selects activity, the soft keyboard is always hidden
  • State always hidden: when the main window of the activity gets the focus, the soft keyboard is always hidden
  • Statevisible: soft keyboards are usually visible
  • State alwaysvisible: the state that the soft keyboard always displays when the user selects activity
  • Adjust unspecified: the default setting, usually hidden or displayed at the discretion of the system
  • Adjust resize: this activity always resizes the screen to make room for the soft keyboard
  • Adjustpan: the content of the current window will be automatically moved so that the current focus is never covered by the keyboard and the user can always see the part of the input content

4、<intent-filter>


<intent-filter  android:icon="drawable resource" android:label\="string resource" android:priority\="integer" >

    <action />

    <category />

    <data />

</intent-filter> 
  • Priority attribute

Orderly broadcasting is mainly based on the declared priority. If a is higher than B, then the broadcasting is transmitted to a first and then to B. Priority is determined by setting the priority attribute. The range is from – 1000 to 1000. The higher the number, the higher the priority.
The data that will be set in the intent filter includes action, data and category. That is to say, the filter will only compare with these three kinds of data in the intent.

  • Action attribute

Action is very simple, only android:name This property. common android:name The value is android.intent.action . main, indicating that this activity is the entry point for the application.

  • Category property

Category only android:name Property. common android:name The value is android.intent.category . launcher (the highest priority component that determines whether the application is displayed in the program list)

  • Data attribute

<data  android:host="string" android:mimeType\="string" 
android:path\="string" android:pathPattern\="string" 
android:pathPrefix\="string" android:port\="string" 
android:scheme\="string"
/>
  • Each < data > element specifies a URI and a data type (MIME type). Its four properties scheme, host, port and path correspond to each part of the URI: scheme://host :port/path。 The scheme value is generally “HTTP”, host is the package name, port is the port number, and path is the specific address.
    Where host and port together constitute the URI’s credentials (authority). If host is not specified, port will also be ignored. For authority to make sense, scheme must also be specified. For path to make sense, scheme + authority must also be specified.
  • MimeType (specify data type). If mimeType is’ image ‘, data of image type will be obtained from the specified address of content provider. There are also “video” and so on. If it is set to video / MP4, it means that the video file in MP4 format is obtained in the specified address
  • And pathpattern and pathprefix are mainly used to format path

From: https://www.jianshu.com/p/1a8df0a8707c

It’s not easy for Xiaobian. If there is any harvest, wechat will give Xiaobian a drink

about AndroidManifest.xml Analysis and explanation

Sunflower classic of single dog, please pay attention to it!
about AndroidManifest.xml Analysis and explanation