Configuration and acquisition of meta data extension element data in manifest

In the androidmanifest.xml manifest file, we sometimes see the following configuration contents starting from the < meta data... > element:

Tag < meta data > is used to provide additional data for components. It itself is a key value pair, and you can customize the name and value. It can be included in the following components: < activity >, < Application >, < Service > and < receiver >

1、 How to configure < mate data... > elements:

The configuration syntax of tag < meta data > elements is as follows:

Note: general values can be specified through the value attribute, but if you want to specify the ID of a resource, you need to use the resource attribute to configure it.

As shown in the following configuration:

Specified API_ The key value is the API stored in the resource file string_ Key values such as aizasybhbfogvqclaa8p1jjeqazhico2nfiybbo are configured as follows:

The specified resid value is res_ ID instead of res in string_ ID value 2. How to obtain the value of < mate data... > element configuration: 1. Configure the < mate data... > element XML code segment under the < application... > element:

Java snippet:

2. Configure the XML code snippet of the < mate data... > element under the < activity... > element:

Java snippet:

3. Configure the < mate data... > element under the < service... > element

XML snippet:

Java snippet:

4. Configure the < mate data... > element XML code snippet under the < receiver... > element:

Java snippet:

Meta data is the child tag under application, activity, activity alias, provider, receiver and service in the application manifest file androidmanifest.xml, which has more parent tags than intent filter. Statistical services like Youmeng generally only need an appid, which only needs to be defined in the application. If you want to add meta data to a component, Then meta data must be defined in its component declaration.

In fact, when we get the meta data, it is a bundle. Knowing this, we can not be afraid of it. If you don't believe it, look.

public Bundle MetaData;

Let's take a look at the application scenario. Define appid in the application. We can also directly give a resource to meta data

Get the meta data method in the application:

You can see that the print is:

If we use it in the following way:

When obtaining, we get the ID of r.id. we also need getresource. Get... To obtain it. Let's test:

Logcat can see:

Now that you know how to get the parameters in the application, others are the same.

As an extended application scenario, we all know that the multi application opening function of Android system, that is, if you have three browsers, when we send a URL, if there is no default browser, we will choose a browser.

Now we like the pop-up selection interface. Each application that can receive this action can introduce itself. Small characters are displayed on the bottom of the selection interface.

For this requirement, we certainly don't mean to remember the introduction of each application in advance, and this must control inversion, that is, each application provides its own introduction separately. At this time, meta data works. We can add a meta data called title to each activity of an application that does a public jump, so we can get it. How to get it? Look at the following operations. (I can suddenly imagine this example, OMG)

Operation 1: use packagemanager to query intent. This function is often used to judge whether an intent has a recipient, such as selecting pictures from an album. In order to prevent the absence of an album, this judgment is often made.

Get the list < resolveinfo > activities. What do you do next?

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
分享
二维码
< <上一篇
下一篇>>