Android Gets the value of manifest in <meta-data> components

Source: Internet
Author: User

The previous time guide completed the game development project. Which is used for packing in bulk.

The network currently on the market is not submitted. However, the game ID number is changed by setting the meta_data> in manifest to get the relevant number of references. The game ID changes and then the game content changes. It was in the activity that I wrote the number of references.

I checked some papers today and concluded.

Are included in the <activity>, <application>, <service>, and <receiver> elements, different parent elements, and the methods that are read at the time of application are also different. They all have the relevant info read. 1: In the Activity app <meta-data> elements.     XML snippet:   <activity...>       <meta-data android:name= "Data_name "Android:value=" Hello my activity ></meta-data>    </activity>       Java Code Snippets:   activityinfo Info=this.getpackagemanager ()                 & nbsp         Getactivityinfo (Getcomponentname (),                &N Bsp         packagemanager.get_meta_data);    String msg =info.metadata.getstring ("Data_name ");    LOG.D (TAG," msg = = "+ msg);  2: Apply <meta-data> element in application.    xml Code snippet:  <application...>       <meta-data android:value= "Hello my Application "Android:name=" Data_name "></meta-data>   </application>     java Code snippet:    ApplicationInfo appInfo = This.getpackagemanager ()                                   Getapplicationinfo (Getpackagename (),                  & nbsp       packagemanager.get_meta_data);    String msg=appinfo.metadata.getstring ("Data_name");     LOG.D (TAG, "msg = =" + msg);  3: In the Service Application <meta-data> element.    xml Code snippet:   <service android:name= "MetadataService" >      <meta-data android:value= "Hello my Service" android:name= "Data_name" ></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 ("Data_name");    LOG.D (TAG, "msg = =" + msg);  4: Application <meta-data> element in receiver.

   xml Code snippet:    <receiver 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 snippet:    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);

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Android Gets the value of manifest in &lt;meta-data&gt; components

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.