【问题标题】:Intent object not triggering intent-filter意图对象未触发意图过滤器
【发布时间】:2026-01-21 01:40:02
【问题描述】:

也许我误解了Intents 和intent-filters 的工作原理,但在我看来,这应该是一个直截了当的案例。但是,它不起作用。

这是我要发送的意图:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setType("vnd.android.cursor.item/vnd.connectsy.event");
startActivity(i);

这里是意图过滤器:

<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>

最后,我收到的错误:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=vnd.android.cursor.item/vnd.connectsy.event }

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    Here's the answer

    Android 会处理所有隐式意图 传递给 startActivity() 就好像他们 至少包含一个类别: “android.intent.category.DEFAULT”( CATEGORY_DEFAULT 常量)。所以, 愿意接受的活动 隐含意图必须包括 “android.intent.category.DEFAULT”在 他们的意图过滤器。

    添加

    <category android:name="android.intent.category.DEFAULT" />
    

    到 AndroidManifest.xml 中的意图过滤器

    【讨论】: