<span id="Label3"></p><p><p>,<meta-data> elements can be used as child elements in androidmanifest.xml, and are included in <activity>, <application>, <service>, and < Receiver> element, but<br>Different parent elements, and the methods that are read when they are applied are also different.</p></p><p><p>First: the use of application:</p></p><p><p>XML sample:</p></p><p><p><application><strong><br><span style="color: #ff0000;"><meta-data android:value= "test" android:name= "meta_value" ></meta-data></span><br></strong></application></p></p><p><p>Java Extract Meta-data information:</p></p><p><p>ApplicationInfo appInfo = This.getpackagemanager (). getapplicationinfo (getpackagename (), Packagemanager.get_meta_ DATA);<br>String data = appInfo.metaData.getString ("meta_value");<br>System.out.println ("meta_value:" +data);</p></p><p><p>Application Scenarios:</p></p><p><p>General Settings Map key, Aurora push secret key and other information</p></p><p><p><meta-data android:name= "com.baidu.lbsapi.API_KEY" <em style="line-height: 1.5;">android:value= "xxxxxx"/></em></p></p><p><p><em id="__mceDel" style="line-height: 1.5;"><meta-data</em> <em id="__mceDel" style="line-height: 1.5;">android:name= "jpush_appkey"</em> <em id="__mceDel" style="line-height: 1.5;">android:value= "xxxxx"/></em></p></p><p><p><em style="line-height: 1.5;"></em> second: in the use of activity:</p></p><p><p>XML sample:</p></p><p><p><activity><strong><br><span style="color: #ff0000;"><meta-data android:value= "test" android:name= "<strong>meta_value</strong>" ></meta-data</span>><br></strong></activity></p></p><p><p>Java Extract Meta-data information:</p></p><p><p>Activityinfo info = This.getpackagemanager (). getactivityinfo (getcomponentname (), packagemanager.get_meta_data);<br>String data = info.metaData.getString ("meta_value");<br>System.out.println ("meta_value:" +data);</p></p><p><p>Application Scenarios:</p></p><p><p>A fixed value needs to be referenced in a specific activity and can be configured in Xml.</p></p><p><p>Third: the use of receiver in the Case:</p></p><p><p>XML sample:</p></p><p><p><receiver android:name= "metadatareceiver" ><br><span style="color: #ff0000;"> <strong><meta-data android:value= "test" android:name= "meta_value" ></meta-data></strong></span><br><intent-filter><br><action android:name= "android.intent.action.PHONE_STATE" ></action><br></intent-filter><br></receiver></p></p><p><p>Java Extract Meta-data information:</p></p><p><p>ComponentName cn=new componentname (context, metadatareceiver.class);<br>Activityinfo info=context.getpackagemanager (). getreceiverinfo (cn, packagemanager.get_meta_data);<br>String data=info.metadata.getstring ("meta_value");<br>System.out.println ("meta_value:" +data);</p></p><p><p><em style="line-height: 1.5;"> </em>Iv: usage in service:</p></p><p><p>XML sample:</p></p><p><p><service android:name= "metadataservice" ><strong><br><span style="color: #ff0000;"><meta-data android:value= "hello my service" android:name= "mymsg" ></meta-data></span><br></strong></service></p></p><p><p>Java Extract Meta-data information:</p></p><p><p>ComponentName cn=new componentname (this, metadataservice.class);<br>ServiceInfo info=this.getpackagemanager (). getserviceinfo (cn, packagemanager.get_meta_data);<br>String msg=info.metadata.getstring ("mymsg");<br>System.out.println ("mymsg:" +msg);</p></p><p><p>Simple record of using <meta-data> in Android</p></p></span>
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