,<meta-data> elements can be used as child elements in Androidmanifest.xml, and are included in <activity>, <application>, <service>, and < receiver> element, but
Different parent elements, and the methods that are read when they are applied are also different.
1: Application in activity.
XML snippet:
<activity...>
<meta-data android:name= "mymsg" android:value= "Hello my Activity" ></META-DATA>
</activity>
java code snippet:
activityinfo Info=this.getpackagemanager ()
. Getactivityinfo (Getcomponentname (),
Packagemanager.get_meta_ DATA);
String msg=info.metadata.getstring ("mymsg");
System.out.println ("mymsg:" +msg);
2: Application in Application.
XML snippet:
<application...>
<meta-data android:value= "Hello my Application" android:name= "mymsg" ></META-DATA>
</ Application>
java code snippet:
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 snippet:
<service android:name= "MetadataService" >
<meta-data android:value= "Hello my Service" android:name= "mymsg" ></meta-data>
</service>
Java Code snippet:
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: Application in receiver.
XML Code snippet:
<receiver android:name= "Metadatareceiver" >
<meta-data android:value= "Hello my Receiver" android:name= "mymsg" ></meta-data>
<intent-filter>
<action android:name= "Android.intent.action.PHONE_STATE" ></action>
</intent-filter>
</receiver>
Java Code snippet:
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);
The above example runs through the android2.1