Android reads the elements in androidmanifest. xml

Source: Internet
Author: User

In androidmanifest. XML, the <meta-data> element can be used as a child element and is contained in <activity>, <Application>, <service>, and <Cycler> elements,
Different parent elements have different reading methods in the application.

1: Application in activity.
XML Code Section:
<Activity...>
<Meta-data Android: Name = "mymsg" Android: value = "Hello my activity"> </meta-data>
</Activity>

Java code segment:
Activityinfo info = This. getpackagemanager ()
. Getactivityinfo (getcomponentname (),
Packagemanager. get_meta_data );
String MSG = info. Metadata. getstring ("mymsg ");
System. Out. println ("mymsg:" + MSG );

2: Application in the application.
XML code segment:
<Application...>
<Meta-data Android: value = "Hello my application" Android: Name = "mymsg"> </meta-data>
</Application>

Java code segment:
Applicationinfo appinfo = This. getpackagemanager ()
. Getapplicationinfo (getpackagename (),
Packagemanager. get_meta_data );
String MSG = appinfo. Metadata. getstring ("mymsg ");
System. Out. println ("mymsg:" + MSG );

3: Application in service.
XML code segment:


Java code segment:
Componentname Cn = new componentname (this, metadataservice. Class );
Serviceinfo info = This. getpackagemanager ()
. Getserviceinfo (CN, packagemanager. get_meta_data );
String MSG = info. Metadata. getstring ("mymsg ");
System. Out. println ("mymsg:" + MSG );

4: Applications in the worker er.
XML code segment:
<Receiver Android: Name = "metadatareceiver">
<Meta-data Android: value = "Hello my Explorer" Android: Name = "mymsg"> </meta-data>
<Intent-filter>
<Action Android: Name = "android. Intent. Action. phone_state"> </Action>
</Intent-filter>
</Cycler>
Java code segment:
Componentname Cn = new componentname (context, metadatareceiver. Class );
Activityinfo info = context. getpackagemanager ()
. Getreceiverinfo (CN, packagemanager. get_meta_data );
String MSG = info. Metadata. getstring ("mymsg ");
System. Out. println ("mymsg:" + MSG );

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.