Android获取Manifest中<meta-data>元素的值
转自: http://www.2cto.com/kf/201303/194824.html
android 开发中:
<activity...> <meta-data android:name="data_Name" android:value="hello my activity"></meta-data> </activity>
ActivityInfo info=this.getPackageManager() .getActivityInfo(getComponentName(), PackageManager.GET_META_DATA); String msg =info.metaData.getString("data_Name"); Log.d(TAG, " msg == " + msg );
<application...> <meta-data android:value="hello my application" android:name="data_Name"></meta-data> </application>
ApplicationInfo appInfo = this.getPackageManager() .getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); String msg=appInfo.metaData.getString("data_Name"); Log.d(TAG, " msg == " + msg );
<service android:name="MetaDataService"> <meta-data android:value="hello my service" android:name="data_Name"></meta-data> </service>
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 );
<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>
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 );
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。