In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what the role of AndroidManifest.xml, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Functions: 1, describe the package name of app; 2, describe the android system version information used by app; 3, describe the version information of app itself, so that for the two versions of the same app, the system can distinguish which is the new version and which is the old version; 4, describe the components exposed by the application, and so on.
We all come across a file when we are doing APP development: AndroidManifest.xml. It has been a few months since I first started Android development, but I still have little knowledge of this file, only that it is for configuration. But what exactly is the use of what is in this document and how to use it has never been understood. Take the opportunity of working on the project to study this document carefully.
The best way to study AndroidManifest.xml is to understand the role of each field in the project in detail against the official documentation and make some changes to verify it.
What is AndroidManifest? what file is AndroidManifest.xml?
The official interpretation of AndroidManifest is the application list (manifest means waybill). 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 APP, and the system needs to run the APP code according to the contents to display the interface.
AndroidManifest.xml is a file in the root directory after each apk (zip) file is unzipped. Each apk must contain an AndroidManifest.xml file with the same name.
What is the purpose of AndroidManifest.xml?
The package name that describes the app:
Android devices distinguish between different app, and if each app is a person, the package name is equivalent to that person's name (to prevent malware from impersonating other app, the upgrade overlay installation can be successful only if the package name and signature of the new app are the same as the old app).
Describe the android system version information used by app:
Because the android system is constantly upgraded, the new system version will add new API, but there is no such API on the old Android device, so there will be a problem that the new version of the application uses the new API but runs on the old system (calling the new API application on the old system will crash), so it is necessary to specify which is the minimum version of the android system supported by this application. For example, setting minSdkVersion to 19 means that the application runs well on API19 and above.
Describe the version information of app itself, so that for two versions of the same app, the system can tell which version is the new version and which is the old version.
A very important role is to describe the components (or interfaces) exposed by the application:
Each of the four major components of Activity,Service,Provider,BroadcastReceiver can be run independently and can be used as an entry point for app startup.
AndroidManifest.xml can tell the system which Activity; to enter after clicking the application icon to tell the system that a certain class of the application (a subclass of BroadcastReceiver) needs to listen for network changes (broadcast); inform the system that the application can provide services (ContentProvider and Service); inform the system that certain classes of the application can handle specific requests (such as opening files with pdf extensions); and so on.
Other things that need to be communicated to the system directly in text: such as the permission to apply, the subject of the application, and so on.
In the final analysis, there is too much information that the app of the Android system needs to tell the system directly through text.
A real AndroidManifest.xml file
This is a file in the teapots project in the official Google example, and we will analyze the meaning of the field for this file. The meaning of the field refers to the official document.
element
First, all xml must contain elements. This is the root node of the file. It must contain elements and indicate the xmlns:android and package attributes.
Attributes in an element
Xmlns:android
This attribute defines the Android namespace. Must be set to "http://schemas.android.com/apk/res/android"". Do not modify it manually.
Package
This is a complete Java language style package name. The package name consists of English letters (uppercase and lowercase), numbers and underscores. Each individual name must begin with a letter.
When building an APK, the build system uses this attribute to do two things:
1. Generate the R.java class with this name as the namespace (used to access APP resources)
For example, if package is set to com.sample.teapot, then the generated R class is: com.sample.teapot.R
2, used to generate the complete class name of the class defined in the manifest file. For example, package is set to com.sample.teapot, and the activity element is declared as, the full class name is com.sample.teapot.MainActivity.
The package name also represents a unique application ID that is used to publish the application. However, it is important to note that at the last step of the APK build process, the package name is replaced by the applicationId attribute in the build.gradle file. If the values of the two attributes are the same, then everything is fine, and if they are not the same, be careful.
Android:versionCode
The internal version number. Used to indicate which version is updated. This number is not displayed to the user. What is displayed to the user is versionName. This number must be an integer. Hexadecimal cannot be used, that is, the parameter "0x1" is not accepted.
Android:versionName
The version number displayed to the user.
Elements in an element
element
Google Play uses the value of this element to filter applications on devices that never meet the needs of the application.
The purpose of this thing is to tell others about the hardware or software conditions on which APP depends. It shows which functions of APP can change with the device.
Be aware that each function must be specified in a separate element, and multiple elements are required if you want multiple functions. For example, the device is required to have both Bluetooth and camera functions:
Properties of
Android:name
This property specifies the hardware or software functionality to be used by APP as a string.
Android:required
If the value of this property is true, it means that the feature is required or the application will not work. If it is false, the application will use the feature if necessary, but it will work without it.
Android:glEsVersion
Indicates the version of Opengl ES required by the application. The high 16 bits represent the major version number, and the low 16 bits represent the minor version number. For example, if you want version 3.2, it's 0x00030002. If you define more than one glEsVersion, the application automatically enables the highest setting.
element
This element describes the configuration of the application. This is a necessary element, it contains many child elements to describe the components of the application, and its attributes affect all sub-components. Many properties, such as icon, label, permission, process, taskAffinity, and allowTaskReparenting, can be set to default values.
Properties of
Android:allowBackup
Indicates whether APP is allowed to be added to the structure of backup and restore. If set to false, then the application will not be backed up and restored. The default is true.
Android:fullBackupContent
This property points to a xml file that contains the full backup rules for automatic backups. These rules define which files need to be backed up. This property is an optional property. By default, automatic backups contain most app files.
Android:supportsRtl
Declare whether your APP supports RTL (Right To Left) layout. If set to true, and targetSdkVersion is set to 17 or higher. A lot of RTL API will be concentrated so that your application can display the RTL layout. If set to false or targetSdkVersion is set to 16 or lower. Which RTL API doesn't work.
The default value of this property is false.
Android:icon
The icon for APP, and the default icon for each component. You can customize the icon in the group price. This property must be set to a reference to a paintable resource that must contain images. The system does not set the default icon. For example, mipmap/ic_launcher refers to the following resources
Android:label
A user-readable label, as well as the default label for all components. Subcomponents can define their own tags with their label attribute, or use this tag if they don't.
The label must be set to a reference to a string resource. So that they can be located like anything else, such as @ string/app_name. Of course, for the convenience of development, you can also define a raw string.
Android:theme
This property, which defines the theme used by the application, is a reference to the style resource. Each activity can also set its own theme with its own theme property.
Android:name
The full name of the Application subclass. Including 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 is not required by most APP. Without this property, Android starts an instance of the Application class.
element
This element declares an Activity (Activity class subclass) that implements the visual interface of the application. This is a necessary child element in the element. All Activity must be represented by elements in the manifest file. Any Activity not declared here is not visible to the system and will never be executed.
Android:name
The name of the Activity class, a subclass of the Activity class. The property value is a 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 element. Once the application is released, the name should not be changed.
There is no default value and the name must be specified.
Android:label
Activity tag, which can be read by the user. The label is displayed on the screen when Activity is activated. If it is not set, use the label property in. The requirements for setting properties are the same as in.
Android:configChanges
Lists the configuration change messages that Activity will handle itself. When a configuration change occurs at run time, Activity is closed and restarted by default, but using this property to declare that the configuration will prevent Activity from restarting. Instead, Activity stays running, and the system calls its onConfigurationChanged () method.
Note: use this attribute should be avoided and should only be used as a last resort. For more information about how to properly handle restarts caused by configuration changes, read handling run-time changes.
There are many items that can be set by this property, and the commonly used items are listed here:
Orientation
The screen rest assured that changes have taken place, such as the user rotating the device.
KeyboardHidden
Keyboard accessibility has changed, such as when the user displays a hardware keyboard
Android:launchMode
Instructions on how to start Activity. There are four instructions:
"standard"
"singleTop"
"singleTask"
"singleInstance"
Standard is the default. These patterns are divided into two main categories: "standard" and "singleTop" are the same category. The Activity for this mode can be instantiated multiple times. An instance can belong to any task and can be located anywhere in the Activity stack. "singleTask" and "singleInstance" are of the same category. This mode can only start tasks, which are always at the root of the Activity stack. In addition, the device can only retain one instance of Activity at a time.
When set to singleTask, the system creates an Activity at the root of the new task and passes the Intent to it. If an Activity instance already exists, instead of creating a new Activity instance, the Intent is passed to it by calling the instance's onNewIntent () method.
Android:theme
Set the theme format, similar to theme in.
element
Specifies an additional data item that is a name-value pair and is provided to its parent component. This data forms a Bundle object that can be used by the PackageItemInfo.metaData field. Although multiple element tags can be used, this is not recommended. If you have multiple data items to specify, it is recommended that you merge multiple data items into a single resource and then use one to include it.
The 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.
element
Indicates with what intent the activity can be started. This element has several child elements that can be contained. Let's start with these two:
element
Indicates what action activity starts as, and android.intent.action.MAIN indicates that it starts as the main activity.
element
This is the additional category information for the action element, and android.intent.category.LAUNCHER indicates that this activity is the highest priority Activity for the current application.
These are all the contents of the article "what are the functions of AndroidManifest.xml?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.