转自: 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 );