Detailed explanation of manifest.xml file in Android

Detailed explanation of manifest.xml file in Android

Each Android project contains a manifest file, androidmanifest.xml, which is stored at the bottom of the project hierarchy. The manifest can define the structure and metadata of an application and its components.

It contains the nodes of each component (activity, service, content provider and broadcast receiver) that makes up the application, and uses intent filters and permissions to determine how these components interact with each other and with other applications.

It also provides various attributes to specify the metadata of the application (such as its icon or theme) and additional top-level nodes that can be used for security settings and unit testing, as described below.

The manifest consists of a root manifest tag with a package attribute that sets the project package. It usually contains an xmlns: Android attribute to provide some system attributes used within the file. The following XML code snippet shows a typical declaration node:

The manifest tag contains nodes that define application components, security settings, and test classes that make up the application. Some common manifest node tags are listed below, and some XML code snippets illustrate how they are used.

1.application

A manifest can only contain one application node. It uses various attributes to specify various metadata for the application, including titles, icons, and topics. It can also be used as a container containing activity, service, content provider, and broadcast receiver tags to specify application components.

2.activity

Each activity displayed by the application requires an activity tag and uses the Android: name attribute to specify the name of the class. This must include the core startup activity and all other screens or dialog boxes that can be displayed. A runtime exception will be thrown when starting any activity that is not defined in the manifest. Each activity node allows the use of the intent filter sub tag to specify which intent starts the activity.

3.provider

The provider tag is used to describe each content provider in the application. Content providers are used to manage database access and sharing within and between programs.

4.receiver

By adding the receiver tag, you can register a broadcast receiver without starting the application in advance. The broadcast receiver is like a global event listener. Once it is registered, it will execute immediately as long as its matching intent is broadcast by the application. This process can be fully automated by registering a broadcast receiver in the declaration. If a matching intent is broadcast, the application will start automatically and your registered broadcast receiver will start running.

5.service

As one of the four components of Android, service plays a very important role in every application. It is mainly used to process some time-consuming logic in the background, or to perform some tasks that need to run for a long time.

6. uses-permission

As part of the security model, the uses permission tag declares the permissions defined by you, which are necessary for the normal execution of the application. When installing the program, all the permissions you set will be told to users, who will decide whether to agree or not. Permissions are required for many local Android services, especially those that need to pay or have security problems (for example, dialing, receiving SMS, or using location-based services). As shown below, third-party applications, including your own applications, can also specify permissions before providing access to shared program components.

7.permission

Before you can restrict access to an application component, you need to define a permission in the manifest. You can use the permission tag to create these permission definitions. The application component can then request these permissions by adding the Android: permission attribute. After that, other applications need to include the uses permission tag in their list (and authorize it) before they can use these protected components.

In the uses permission tab, you can specify the level of allowed access permissions (normal, dangerous, signature, signatureorsystem), a label attribute and an external resource. The external resource should contain a description of the risks of granting such permissions.

8.instrumentation

The instrumentation class provides a framework for running tests on activities or services while the application is running. They provide methods to monitor applications and their interactions with system resources. For each test class created for your application, you need to create a new node.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>