マニフェストに次の宣言があるアプリケーション X があるとします。
<activity android:name=".MyActivity"
android:label="@string/app_name">
<!-- filter: This activity can be the default view action for a row in
RawContacts -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="vnd.android.cursor.item/raw_contact" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
このアプリケーションが「デフォルト オプション」であるかどうかを確認するには (この例では何でも)、次のようにします。
/**
* Returns true if the supplied component name is the preferred activity
* for any action.
* @param component The ComponentName of your Activity, e.g.
* Activity#getComponentName().
*/
boolean isDefault(ComponentName component) {
ArrayList<ComponentName> components = new ArrayList<ComponentName>();
ArrayList<IntentFilter> filters = new ArrayList<IntentFilter>();
getPackageManager().getPreferredActivities(filters, components, null);
return components.contains(component);
}