Android obtains the value of the <meta-data> element in Manifest, manifestmeta-data
The development of the game strategy project was completed some time ago. It uses batch packaging. Instead of submitting on the online market, you can set Meta_data> in Manifest to obtain relevant parameters. The game ID changes, the game ID changes, and the game content changes. At that time, the parameters were written in the Activity. Today I checked some files and summarized them.
It is included in <activity>, <application>, <service>, and <Cycler> elements. Different parent elements have different reading methods during the application. They all have related Info reads. 1: Apply the <meta-data> element in the Activity. Xml code segment: <activity...> <meta-data android: name = "data_Name" 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 ("data_Name"); Log. d (TAG, "msg =" + msg); 2: Apply the <meta-data> element in the application. Xml code segment: <application...> <meta-data android: value = "hello my application" android: name = "data_Name"> </meta-data> </application> java code segment: ApplicationInfo appInfo = this. getPackageManager (). getApplicationInfo (getPackageName (), PackageManager. GET_META_DATA); String msg = appInfo. metaData. getString ("data_Name"); Log. d (TAG, "msg =" + msg); 3: Apply the <meta-data> element in the service. Xml code segment: <service android: name = "MetaDataService"> <meta-data android: value = "hello my service" android: name = "data_Name"> </meta-data> </service> 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 ("data_Name"); Log. d (TAG, "msg =" + msg); 4: In the receive R application <meta-data> element. Xml code segment: <er android: name = "MetaDataReceiver"> <meta-data android: value = "hello my receiver" android: name = "data_Name"> </meta-data> <intent-filter> <action android: name = "android. intent. action. PHONE_STATE "> </action> </intent-filter> </receiver> 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 ("data_Name"); Log. d (TAG, "msg =" + msg );
In android, there are five elements in data. How can I obtain the value of the second element?
String x = data [1]; Prerequisite: Your data = {a, B, c, d, e}
How to write the sqllite configuration file for android connection (similar to webconfig)
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 segment:
<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 );
A component element can contain any number of meta-data sub-elements. All their values are collected in the Bundle object and can be used as the PackageItemInfo. metaData field of the component. The general value can be specified through the value attribute, but if you want to specify a resource id as a value, you must use the resource attribute instead. For example, the following code specifies the zoo name stored in the @ string/kangaroo resource. <Meta-data android: name = "zoo" android: value = "@ string/kangaroo"/> On the other hand, the resource attribute is used to specify the resource ID of the zoo, it is not the resource value stored in the resource. <Meta-data android: name = "zoo" android: resource = "@ string/kangaroo"/> to provide components with multiple complex data, multiple meta-data elements are not recommended here. We recommend that you store the data in a resource file and use the resource attribute to notify the component of its id.
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 (getPa... the remaining full text>