Perhaps I'm misunderstanding how Intent
s and intent-filter
s work, but it seems to me that this should be a straight-forward case. However, it's not working.
Here is the Intent I'm sending:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setType("vnd.android.cursor.item/vnd.connectsy.event");
startActivity(i);
And here is the intent-filter:
<activity android:name=".events.EventView">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="vnd.android.cursor.item/vnd.connectsy.event" />
</intent-filter>
</activity>
And finally, the error I'm recieving:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=an开发者_JS百科droid.intent.action.VIEW typ=vnd.android.cursor.item/vnd.connectsy.event }
Here's the answer:
Android treats all implicit intents passed to startActivity() as if they contained at least one category: "android.intent.category.DEFAULT" (the CATEGORY_DEFAULT constant). Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters.
Add
<category android:name="android.intent.category.DEFAULT" />
to your intent filter in AndroidManifest.xml
精彩评论