I want to use addIntentOptionsto manage my menus whenever possible. This seems like the cleanest way to secure them. Instead of explicitly detailing the actions, just ask for a menu that lists all the actions available for my data item.
So, I'm trying to put together a context menu for ListView. It works great. The only problem is that I have an activity that has two intentions that consume my data type, and only the first appears.
Related activities in AndroidManifest.xml
<activity android:name=".ui.MyActivity" android:label="The title">
<intent-filter android:label="First context label">
<action android:name="com.sample.action.FIRST_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
<data android:scheme="myscheme" />
</intent-filter>
<intent-filter android:label="Second context label">
<action android:name="com.sample.action.SECOND_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
<data android:scheme="myscheme" />
</intent-filter>
</activity>
Code for creating a context menu
@Override
public void onCreateContextMenu(ContextMenu menu, View view,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
Uri uri = Uri.fromParts("myscheme", getOpaqueUriOfSelectedItem(view), null)
Intent intent = new Intent(null, uri);
intent.addCategory(Intent.CATEGORY_SELECTED_ALTERNATIVE);
menu.addIntentOptions(
0,
0,
0,
this.getComponentName(),
null,
intent,
0,
null);
}
, . , , . Android , .
, , MyActivity. , , .
. , ( , ), , , , , getIntent().getAction() .
. , , ?
- -, , , .
. CommonsWare queryIntentActivityOptions. menu.addIntentOptions .
PackageManager pm = getPackageManager();
final List<ResolveInfo> available =
pm.queryIntentActivityOptions(this.getComponentName(), null, intent, 0);
, available MyActivity. , addIntentOptions, , queryIntentActivityOptions -.