Introduced
Android provides a custom configuration in the form of meta-date using key-value pairs. Generally used as channel identification. Can be used under the <application>,<activity>,<activity-alias>,<provider>,<receiver> node. All values are stored in the same bundle and can be used with Packageiteminfo.metadata channel data.
form of Use:
1 <meta-data android:name= "string" 2 android:resource= "Resource Specification" 3 Android:value= "string"/>
Resource and value can be used directly, but note that if you use the
1 <meta-data android:name= "Zoo" android:value= "@string/kangaroo"/>
Then you get the ID value, which is the number in the R file, not the actual resource value. Instead, use resource to fetch the resource value (using Getint ()).
1 <meta-data android:name= "Zoo" android:resource= "@string/kangaroo"/>
Android:name: Make sure it's the only thing that's OK.
Android:value: The value can be:
1. String use GetString () to get
2. Integers such as "100" are obtained using Getint ()
3. Boolean value: "True", "false" using Getboolean () to get
4. Color value: "#rgb", "#argb", "#rrggbb", or "#aarrggbb" use Getint () to get
5. Floating-point value: "1.2" Using GetFloat ()
Note: The bundle uses a return (string) O; to get the code to get a stringvalue value if you configure a string to be configured with a value of "000", but when the metadata is wrapped into bundles, "000" is parsed into an integer 0, so using GetString () will be null.
Instance:
At the end of the manifest node, add:
1 <meta-data android:value= "googleplay_v165" android:name= "Haiwan_channel"/>
In a custom application inside a method
1 PublicString gethaiwanversion () {2String channel = "";3 Try {4Channel = This. Getpackagemanager (). Getapplicationinfo (Getpackagename (), Packagemanager.get_meta_data). MetaData.getString (" Haiwan_channel ");5}Catch(namenotfoundexception e) {6 e.printstacktrace ();7 }8 returnChannel;9}
Other nodes:
1 //in the Activity app <meta-data> elements. 2Activityinfo info = This. Getpackagemanager ()3 . Getactivityinfo (Getcomponentname (), packagemanager.get_meta_data);4Info.metaData.getString ("Meta_name");5 6 //application <meta-data> elements in application. 7ApplicationInfo AppInfo = This. Getpackagemanager ()8 . Getapplicationinfo (Getpackagename (), packagemanager.get_meta_data);9AppInfo.metaData.getString ("Meta_name");Ten One //in service apps <meta-data> elements. AComponentName cn =NewComponentName ( This, MetadataService.class); -ServiceInfo info = This. Getpackagemanager (). GetServiceInfo (CN, packagemanager.get_meta_data); -Info.metaData.getString ("Meta_name"); the - //applications <meta-data> elements in receiver. -ComponentName cn =NewComponentName (context, metadatareceiver.class); -Activityinfo info =Context.getpackagemanager (). Getreceiverinfo (CN, packagemanager.get_meta_data); +Info.metaData.getString ("Meta_name");
Android reads metadata custom data under application and other nodes under the manifest file