meta-data的使用:攜帶數據進行app間傳遞

(查詢Activity存在與否)link to :http://www.javashuo.com/article/p-mlmpotit-gs.htmljava

<activity
      ……>

  <meta-data android:name="com.android.settings.category" android:value="com.android.settings.category.personal"></meta-data>
  <meta-data android:name="com.android.settings.title" android:resource="@string/applicationLabel"></meta-data>
  <meta-data android:name="com.android.settings.icon" android:resource="@mipmap/ic_settings_dialer"></meta-data>

  <intent-filter>
    <action android:name="com.android.settings.action.EXTRA_SETTINGS" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

 

Intent intent = new Intent(EXTRA_SETTINGS_ACTION);
PackageManager pm = context.getPackageManager();

List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);


Resources res = pm.getResourcesForApplication(resolveInfo.activityInfo.packageName);
Bundle metaData = resolveInfo.activityInfo.metaData;

if (metaData.containsKey(META_DATA_PREFERENCE_TITLE)) {
  title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
}
相關文章
相關標籤/搜索