Android configuration file (1) and android configuration file

Source: Internet
Author: User

Android configuration file (1) and android configuration file

In AndroidManifest. in the xml file, the <manifest> node is the basic attribute of the entire application, covering the default process name, Application ID, and installation location, system requirements and application versions. It is the root node of the AndroidManifest. xml file. It must contain a <application> node and specify the xmlns: android and package attributes. Its syntax is shown in the following code:


<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"

Package = "string"

Android: sharedUserId = "string"

Android: sharedUserLabel = "string resource"

Android: versionCode = "integer"

Android: versionName = "string"

Android: installLocation = ["auto" | "internalOnly" | "preferExternal"]>

.............

</Manifest>


Among the many attributes described above, except the xmlns and package nodes, the other nodes are optional. Android provides default values for them. Next, we will explain in detail the meanings and functions of these attributes in the <manifest> node.


1. xmlns: android properties -- Define namespaces

This attribute defines the namespace used by the XML file. If you need to specify a special namespace, You need to manually write the code. The basic format is as follows:


Xmlns: <namespace identifier> = "http://schemas.android.com/apk/res/ <complete package name>"


Note: The <> part of the Code must be filled in. Do not miss it!


Let's start with the omnipotent HelloWorld. Open the latest android development tool android studio and create a project named HelloWorld. The project will automatically generate AndroidManifest. xml file. Let's take a look at its structure.




If the "ID" does not match, the result is as follows:


Error message:



The "resource package name" is a required Java package name. If it does not exist, an error will also occur.


You can understand it! The identifiers and resource package names must be uniform and cannot be written as needed. Otherwise, no matter how hard it is, you can only move on. Remember!


2. package properties-Application ID card


The package property uniquely identifies an application. Note that it is unique! Similarly, it is the default name of the application process and the default task (taskAffinity) of each Activity in the application ). Generally, when we create a project, it has a default value. So where do these default names come from? For example:



When this program is run, the Android device starts such a process for this application, for example:



Are you clear? Here, you may come up with an idea: What will happen if I install another application with the same package attribute? The following error is prompted:


Failure [INSTALL_FAILED_ALREADY_EXSIST]


Note: We do not recommend that you modify the value of the package attribute unless otherwise required! The reason is that the package uniquely identifies the attributes of our application. If you try to change its value, the system usually considers it a different application, users with applications of the previous version cannot own the new version of the application.


3. android: sharedUserId Attribute-shared data


This attribute defines the Linux User ID to be shared with other applications. By default, the Android system assigns a unique user ID to each application. However, when this attribute is set to the same value in multiple applications, they share a user ID. The advantage of doing so is that they can access each other's data, and they will run in the same process as needed. The Helloworld application does not set this attribute, which means that it does not share with other applications, so that they need to communicate with each other through other means (such as inter-process communication.


The attributes related to the android: sharedUserId attribute include android: sharedUserLabel, which defines a user-readable tag for the shared user ID. This tag must be set with string resources and cannot use native strings. This attribute is referenced in API LEVEL3 and makes sense only when the sharedUserId attribute is set.


4. android: versionCode Attributes -- Internal version number


Android: The versionCode attribute is an internal version number used to determine whether the version is later than the other version. A larger number indicates that the version is newer. It is not the version number displayed to the user, but the number set by the versionName attribute. The version number determines the behavior of some services, such as whether to perform backup and restore operations when the application is replaced.


This number must be an integer, such as 100. In addition, we can define this Integer as needed, as long as each successor version can have a larger number. For example, it can be a compilation number.


5. android: versionName attribute -- version number displayed to the user


Android: The versionName attribute value is the version number displayed to the user. It can be set as a reference to an original string or a string resource. This string has no other purpose except to be displayed outdoors. In HelloWorld, the version number displayed to the user is 1.0, for example:



6. android: installLocation property-installation location


This attribute defines the default installation location of the application. There are three optional values in the form:


Android: installLocation = ["auto" | "internalOnly" | "preferExternal"]


The following table describes the meanings of the Three Optional values.


Value Description
Auto Applications may be installed on external storage devices, but by default, the system will install the applications on the internal storage devices. If the memory is insufficient, the system installs the application to an external storage device.
InternalOnly The application must be installed on the internal storage device of the device. If this value is set, the application will never be installed on an external storage device. If the memory is insufficient, the system will not install this APK. If the android: installLocation attribute is not set, internalOnly is the default value of this attribute.
PreferExternal Applications will be installed on external storage devices. if the system does not support external storage devices or the external devices are full, the system will install the application on the internal storage devices.


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.