android - 将 URL 与 Intent 匹配不起作用

标签 android android-intent

我正在编写一个与网站配套的 Android 应用程序,我想让该应用程序拦截某些 URL。我通过 Google 和 SO 找到了多个示例,但没有一个起作用。我创建我的 Intent :

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://xgn.nl/article/" + String.valueOf(id)));

然后从另一个 Activity 启动它(其中 i 是上面的 Intent )

startActivity(i);

应该接收此消息的 Activity 的 Intent 过滤器是:

<activity android:name=".ArticleActivity" android:theme="@style/XGN.Red">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="http" android:host="xgn.nl" android:pathPrefix="/article/" android:mimeType="text/*" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>

我也尝试过在过滤器中没有 mimeType 。 Intent 解析器看到过滤器,但提示数据与 Intent 中的数据不匹配,并启动浏览器。

我做错了什么?

最佳答案

实际上,我在发布后 5 秒就解决了它,问题是您需要指定完全限定的类名才能使其工作:)

<activity android:name="nl.xgn.ArticleActivity" android:theme="@style/XGN.Red">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" android:host="xgn.nl" android:pathPrefix="/article/" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
</activity>

编辑:更准确地说,我在 logcat 中看到的错误是错误的。数据类型确实匹配,但它选择了更可见的浏览器类而不是我的延迟定义的 Activity 。指定完整的类名并删除 mimeType 即可实现此目的。

关于android - 将 URL 与 Intent 匹配不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7902807/

相关文章:

android - Android 中的 SQI 和 CQI 值

android - 如何使用 broadcastReceiver onReceive() 将我的 Activity 置于最前面?

android - 如何通过intent-filter和action.SEND_MULTIPLE接收多张电子名片

android - 如何将子 Activity 的结果返回给android中的父 Activity ?

android - 接收到 NFC 后保持当前 Activity

android - 使用 LocalBroadcastManager 时出现 NullPointerException

java - 无法在android中保存实例状态

java - 我如何在 libgdx 的 res 中的字符串 xml 文件中获取定义的字符串?

android - 无法获得与微调器一起工作的 Intent

android - 如何使用 ViewPager 回收 View ?