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 );