Describes Android in providing meta-date using key-value pairs as a way to implement a custom configuration. 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:
<meta-data android:name= "string" android:resource= "resource Specification" android:value= "string"/ >
Resource and value can be used directly, but note that if you use the
<meta-dataandroid: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. and touse resource to fetch resource values (using Getint ()).
<meta-dataandroid: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:
<meta-data android:value= "googleplay_v165" android:name= "Haiwan_channel"/>
Inside a custom application is a method:
/** * Get the channel version configured in manifest * <p>2014-11-14</p> * @return * @author RANDY. ZHANG */public String Gethaiwanversion () {String channel = ""; try {channel = This.getpackagemanager (). Getapplicationinfo (Getpackagename (), Packagemanager.get_meta_data). Metadata.getstring ("Haiwan_channel");} catch (Namenotfoundexception e) {e.printstacktrace ();} return channel;}
Other nodes:
In the Activity app <meta-data> elements. Activityinfo info = This.getpackagemanager (). Getactivityinfo (Getcomponentname (), packagemanager.get_meta_data); Info.metaData.getString ("Meta_name"); Application <meta-data> elements in application. ApplicationInfo appInfo = This.getpackagemanager (). Getapplicationinfo (Getpackagename (), Packagemanager.get_meta _data); AppInfo.metaData.getString ("Meta_name"); In service apps <meta-data> elements. ComponentName cn = New ComponentName (this, metadataservice.class); ServiceInfo info = This.getpackagemanager (). GetServiceInfo (CN, Packagemanager.get_meta_data); Info.metaData.getString ("Meta_name"); Applications <meta-data> elements in receiver. ComponentName cn = New ComponentName (context, metadatareceiver.class); Activityinfo info = Context.getpackagemanager (). Getreceiverinfo (CN, Packagemanager.get_meta_data); Info.metaData.getString ("Meta_name");
Android reads Meta-data custom data under Application nodes under the manifest file