Home >Common Problem >Briefly describe the function of AndroidManifest.xml?
Function: 1. Describe the package name of the app; 2. Describe the version information of the android system used by the app; 3. Describe the version information of the app itself, so that the system can distinguish between two versions of the same app. Which is the new version and which is the old version? 4. Describe the components exposed by the application, etc.
#We will encounter a file when developing APP: AndroidManifest.xml. A few months have passed since I first started developing Android, and I still know little about this file. I only know that it is for configuration. But I have never understood the specific use of the things in this file and how to use them. Take the opportunity of working on the project to study this document carefully.
The best way to study AndroidManifest.xml is naturally to understand the role of each field in the project in detail according to the official documentation, and make some modifications to verify it.
What is AndroidManifest? What kind of file is AndroidManifest.xml?
The official explanation of AndroidManifest is the application manifest (manifest means manifest), Each application must have one in its root directory, and the file name must be exactly the same. This file contains the configuration information of the APP. The system needs to run the APP code and display the interface based on the content inside.
AndroidManifest.xml is a file in the root directory after decompression of each apk (zip) file. Each apk must contain an AndroidManifest.xml file, and the name must be exactly the same.
What is the function of AndroidManifest.xml?
Describe the package name of the app:
Android devices distinguish different apps accordingly. If each app is a person, the package name It is equivalent to this person's name (in order to prevent malware from counterfeiting other apps, only when the package name and signature of the new app are the same as the old app can the upgrade overwrite installation be successful).
Describe the android system version information used by the app:
Because the android system is constantly being upgraded, new system versions will add new APIs, but old Android devices do not have these APIs, then new versions will appear. The problem is that the application uses the new API but runs on the old system (the application will crash when calling the new API on the old system), so it is necessary to indicate the minimum Android system version supported by the application, for example, set minSdkVersion to 19 means that this application has no problem running on devices with API 19 and above.
describes the version information of the app itself, so that the system can distinguish between two versions of the same app. Which is the new version and which one is the old version?
A very important role is to describe the components (or interfaces) exposed by the application:
Activity, Service, Provider , each of the four components of BroadcastReceiver can run independently and can be used as the entry point for app startup.
AndroidManifest.xml can tell the system which Activity to enter after clicking the application icon; it can tell the system that a certain class of this application (a subclass of BroadcastReceiver) needs to monitor network changes and other information (broadcast); it can tell the system that this application can other The application provides services (ContentProvider and Service); informs the system that certain classes of this application can handle some specific requests (such as opening files with pdf extensions); etc.
Other needs Use text to directly inform the system: such as the permissions applied for, the theme of the application, etc.
In the final analysis, the Android system app needs to directly tell the system too much information through text.
A real AndroidManifest.xml file
<manifest> <uses-feature></uses-feature> <application> <!-- Our activity is the built-in NativeActivity framework class. This will take care of integrating with our NDK code. --> <activity> <!-- Tell NativeActivity the name of our .so --> <meta-data></meta-data> <intent-filter> <action></action> <category></category> </intent-filter> </activity> </application> </manifest>
This is a file in the teapots project in Google's official example. We will analyze the meaning of the fields based on this file. The meaning of the fields refers to the official documentation.
First of all, all xml must contain the
xmlns:android
This attribute definition Android namespace. Must be set to "http://schemas.android.com/apk/res/android". Don't modify it manually.
package
This is a complete Java language style package name. The package name consists of English letters (both upper and lower case), numbers and underscores. Each individual name must begin with a letter.
When building an APK, the build system uses this property to do two things:
包名也代表着唯一的application ID,用来发布应用。但是,要注意的一点是:在APK构建过程的最后一步,package名会被build.gradle文件中的applicationId属性取代。如果这两个属性值一样,那么万事大吉,如果不一样,那就要小心了。
android:versionCode
内部的版本号。用来表明哪个版本更新。这个数字不会显示给用户。显示给用户的是versionName。这个数字必须是整数。不能用16进制,也就是说不接受"0x1"这种参数
android:versionName
显示给用户看的版本号。
Google Play利用这个元素的值从不符合应用需要的设备上将应用过滤。
这东西的作用是将APP所依赖的硬件或者软件条件告诉别人。它说明了APP的哪些功能可以随设备的变化而变化。
使用的时候要注意,必须在单独的
<uses-feature></uses-feature> <uses-feature></uses-feature>
android:name
该属性以字符串形式指定了APP要用的硬件或软件功能。
android:required
这项属性如果值为true表示需要这项功能否则应用无法工作,如果为false表示应用在必要时会使用该功能,但是如果没有此功能应用也能工作。
android:glEsVersion
指明应用需要的Opengl ES版本。高16位表示主版本号,低16位表示次版本号。例如,如果是要3.2的版本,就是0x00030002。如果定义多个glEsVersion,应用会自动启用最高的设置。
此元素描述了应用的配置。这是一个必备的元素,它包含了很多子元素来描述应用的组件,它的属性影响到所有的子组件。许多属性(例如icon、label、permission、process、taskAffinity和allowTaskReparenting)都可以设置成默认值。
android:allowBackup
表示是否允许APP加入到备份还原的结构中。如果设置成false,那么应用就不会备份还原。默认值为true。
android:fullBackupContent
这个属性指向了一个xml文件,该文件中包含了在进行自动备份时的完全备份规则。这些规则定义了哪些文件需要备份。此属性是一个可选属性。默认情况下,自动备份包含了大部分app文件。
android:supportsRtl
声明你的APP是否支持RTL(Right To Left)布局。如果设置成true,并且targetSdkVersion被设置成17或更高。很多RTL API会被集火,这样你的应用就可以显示RTL布局了。如果设置成false或者targetSdkVersion被设置成16或更低。哪些RTL API就不起作用了。
该属性的默认的值是false。
android:icon
APP的图标,以及每个组件的默认图标。可以在组价中自定义图标。这个属性必须设置成一个引用,指向一个可绘制的资源,这个资源必须包含图片。系统不设置默认图标。例如mipmap/ic_launcher引用的就是下面的资源
android:label
一个用户可读的标签,以及所有组件的默认标签。子组件可以用他们的label属性定义自己的标签,如果没有定义,那么就用这个标签。
标签必须设置成一个字符串资源的引用。这样它们就能和其他东西一样被定位,比如@string/app_name。当然,为了开发方便,你也可以定义一个原始字符串。
android:theme
This attribute defines the theme used by the application. It is a reference to the style resource. Each activity can also set its own theme using its own theme attribute.
android:name
The full name of the Application subclass. Includes the previous path. For example com.sample.teapot.TeapotApplication. When the application starts, an instance of this class is created first. This attribute is optional and most apps do not require this attribute. In the absence of this attribute, Android will start an instance of the Application class.
This element declares an Activity (subclass of Activity class) that implements the application visual interface. This is a required child element of the
android:name
The name of the Activity class, which is a subclass of the Activity class. The property value is the fully qualified class name, such as com.sample.teapot.TeapotNativeActivity. For convenience, if the first character is a dot ('.'), you need to add the package name in the
There is no default value, the name must be specified.
android:label
Activity label, which can be read by the user. This label will be displayed on the screen when the activity is activated. If not set, the label attribute in
android:configChanges
Lists configuration change messages that the activity will handle on its own. When a configuration change occurs at runtime, the activity is closed and restarted by default, but declaring the configuration with this attribute will prevent the activity from restarting. Instead, the activity remains running and its onConfigurationChanged() method is called.
Note: Use of this attribute should be avoided and should only be used as a last resort. For more information on how to properly handle restarts due to configuration changes, read Handling Runtime Changes.
There are many items that can be set for this attribute. Here are the commonly used items:
android:theme
Set the theme format, similar to the theme in
Specifies an additional data item, which is a name-value pair provided to its parent component. These data will form a Bundle object, which can be used by the PackageItemInfo.metaData field. Although it is possible to use multiple
This element has three attributes:
android:name
Data item name, which is a unique value.
android:resource
A reference to a resource.
android:value
The value of the data item.
##
For more programming-related knowledge, please visit: Programming Learning! !
The above is the detailed content of Briefly describe the function of AndroidManifest.xml?. For more information, please follow other related articles on the PHP Chinese website!