开发者

Intent object not triggering intent-filter

开发者 https://www.devze.com 2023-01-04 15:04 出处:网络
Perhaps I\'m misunderstanding how Intents and intent-filters work, but it seems to me that this should be a straight-forward case. However, it\'s not working.

Perhaps I'm misunderstanding how Intents and intent-filters 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号