Android cainiao study Note 3 ---- explanation of AndroidMainfest. xml and androidmainfest
Each android project contains an AndroidMainfest. xml file, which contains every Acitivity, Service, Content Provider, and Broadcast Receiver node of the application, and use Intent Filter and permissions to determine how these components interact with other applications.
1.Root Node manifest:
Package property: package name of the current application
VersionCode attribute: defines the version of the current application as an integer. This number is added during each version iteration.
VersionName attribute: defines a public version number displayed to the user.
InstallLocation attribute: Specifies whether to allow (or preferred) Installation of applications to external storage (usually SD card ). The value can be preferExternal or auto. If the former is used, the application is installed on the external storage whenever possible, and the latter is determined by the system. If the installLocation attribute is not specified, the current application is installed in the internal storage, instead of being moved to the external storage.
For example:
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "cn. csc. mydemo"
Android: versionCode = "1"
Android: versionName = "1.0 Beta"
Android: installLocation = "preferExternal">
</Manifest>
2. manifestCommon subnodes:
1) uses-sdk:
For example, <uses-sdk
Android: minSdkVersion = "10"
Android: targetSdkVersion = "14"/>
MinSdkVersion attribute: specifies the minimum SDK version required by the application. If this parameter is not specified, the default value is 1.
MaxSdkVersion attribute: the highest SDK version. It is generally not recommended to specify this attribute unless you know that the application cannot run correctly on the platform of the updated version.
TargetSdkVersion attribute: used to specify the platform version used in development and testing. Even if the application does not use any new API, the target SDK should be set to the latest platform version, which is considered a best practice.
2) uses-permission:
Configure the permissions required by the application. When installing the application, all the permissions set will be sent to the user, who decides whether to agree to the installation and use.
For example, <uses-permission android: name = "android. permission. INTERNET"/> requires network permissions.
3) instrumentation:
Used in Unit Testing
For example: <instrumentation
Android: name = "android. test. InstrumentationTestRunner"
Android: targetPackage = "cn. csc. demo"/> specify the package name to be tested.
4) application:
A mainfest file can have only one application node. Its Attributes and subnodes are commonly used.
3. applicationNode:
Example: <application
Android: icon = "@ drawable/ic_launcher"
Android: label = "@ string/app_name">
Icon attribute: Specifies the icon of the current application.
Label attribute: Specifies the title of the current application.
1) activity subnode:
<Activity
Android: name = ". MainActivity"
Android: label = "@ string/app_name">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
Each Activity used in the application requires an Activity subnode. When an Activity not defined in Manifest is started, a runtime exception is thrown. Each Activity node allows the intent-filter subnode to define the Intent used to start the Activity.
Name attribute: Specifies the name of the Activity class.
2) service subnode: the service used by the application
3) provider subnode: Content Provider used by the application
4) receiver subnode: refers to the Broadcast Receiver used by the program.
5) uses-library subnode: used to specify the shared library required by the application