Home > Common Problem > Briefly describe the function of AndroidManifest.xml?

Briefly describe the function of AndroidManifest.xml?

青灯夜游
Release: 2020-11-30 14:00:43
Original
20136 people have browsed it

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.

Briefly describe the function of AndroidManifest.xml?

#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>
Copy after login

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.

element

First of all, all xml must contain the element. This is the root node of the file. It must contain the element and specify the xmlns:android and package attributes.

Attributes in the element

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:

  • 1、生成R.java类时用这个名字作为命名空间(用于访问APP的资源)
    比如:package被设置成com.sample.teapot,那么生成的R类就是:com.sample.teapot.R
  • 2、用来生成在manifest文件中定义的类的完整类名。比如package被设置成com.sample.teapot,并且activity元素被声明成,完整的类名就是com.sample.teapot.MainActivity。

包名也代表着唯一的application ID,用来发布应用。但是,要注意的一点是:在APK构建过程的最后一步,package名会被build.gradle文件中的applicationId属性取代。如果这两个属性值一样,那么万事大吉,如果不一样,那就要小心了。

android:versionCode

内部的版本号。用来表明哪个版本更新。这个数字不会显示给用户。显示给用户的是versionName。这个数字必须是整数。不能用16进制,也就是说不接受"0x1"这种参数

android:versionName

显示给用户看的版本号。

Briefly describe the function of AndroidManifest.xml?

元素中的元素

元素

Google Play利用这个元素的值从不符合应用需要的设备上将应用过滤。

这东西的作用是将APP所依赖的硬件或者软件条件告诉别人。它说明了APP的哪些功能可以随设备的变化而变化。

使用的时候要注意,必须在单独的元素中指定每个功能,如果要多个功能,需要多个元素。比如要求设备同时具有蓝牙和相机功能:

<uses-feature></uses-feature>
<uses-feature></uses-feature>
Copy after login

的属性

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引用的就是下面的资源

Briefly describe the function of AndroidManifest.xml?

android:label

一个用户可读的标签,以及所有组件的默认标签。子组件可以用他们的label属性定义自己的标签,如果没有定义,那么就用这个标签。

标签必须设置成一个字符串资源的引用。这样它们就能和其他东西一样被定位,比如@string/app_name。当然,为了开发方便,你也可以定义一个原始字符串。

Briefly describe the function of AndroidManifest.xml?

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.

Briefly describe the function of AndroidManifest.xml?

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.

Element

This element declares an Activity (subclass of Activity class) that implements the application visual interface. This is a required child element of the element. All activities must be represented by an element in the manifest file. Any activity not declared there is not visible to the system and will never be executed.

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 element. Once the app is published, the name should not be changed.

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 is used. The requirements for setting properties are the same as 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:

  • orientation
    Don’t worry, the screen has changed, for example, the user rotates the device
  • keyboardHidden
    Keyboard accessibility has changed, for example, the user is shown a hardware keyboard
  • android:launchMode
    Instructions on how to launch the Activity. There are four instructions in total:
    "standard"
    "singleTop"
    "singleTask"
    "singleInstance"
    The default is standard. These modes are divided into two categories: "standard" and "singleTop" are one category. Activity in this mode can be instantiated multiple times. Instances can belong to any task and can be located anywhere in the Activity stack. "singleTask" and "singleInstance" are the same class. This mode can only start tasks, which are always at the root of the Activity stack. Additionally, the device can only hold one Activity instance at a time.
    After setting it to singleTask, the system creates the Activity at the root of the new task and sends the Intent to it. If an Activity instance already exists, the system will transfer the Intent to it by calling the instance's onNewIntent() method instead of creating a new Activity instance.

android:theme

Set the theme format, similar to the theme in .

Element

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 element tags, this is not recommended. If there are multiple data items to be specified, the recommended approach is to combine the multiple data items into one resource and then include them using a .

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.

## element

specifies what intent (intent) this activity can be started with. This element can contain several child elements. Let’s first introduce the two we encountered:

element

indicates what action the activity is started as, android.intent.action.MAIN indicates what action it takes to start the activity. The main activity starts.

element

This is additional category information of the action element. android.intent.category.LAUNCHER indicates that this activity is the highest priority for the current application. Activity.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template