android - Intent 对象未触发 Intent 过滤器

标签 android android-intent

也许我误解了 Intentintent-filter 的工作原理,但在我看来,这应该是一个简单的情况。但是,它不起作用。

这是我发送的 Intent :

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

这是 Intent 过滤器:

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

最佳答案

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.

添加

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

到 AndroidManifest.xml 中的 Intent 过滤器

关于android - Intent 对象未触发 Intent 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3120385/

相关文章:

android - 为多个屏幕android创建我的 View

android - 发现多个文件的操作系统独立路径为 'META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version'

android - IllegalStateException : parcel. readString() 不能为空

android - 如何禁用android中线性布局内的所有内容?

java - Android:Intent Extras 未通过 Activity 上下文之外的 startActivity() 传递

android - 使用 ARC 进行自动化测试?

android - viewflipper仅下一个动画

可以在运行时从插件接收自定义逻辑的 Android Activity

android - startActivityforResult 的 RequestCode 类型

android - 相对布局中的 ArrayAdapter - Android