【问题标题】:Do mime type intent filters work on HTTP URLs?MIME 类型意图过滤器是否适用于 HTTP URL?
【发布时间】:2013-05-03 18:55:12
【问题描述】:

有很多示例代码使用IntentFilter"http"mimeType 集合。查看Handling MIME type that is the result of a browser POST in AndroidIntent filter for browsing XML (specifically rss) in androidHow to open my Android app when rss link is opened in browser? 的答案

我的具体用例是 RSS 链接,就像最后两个问题一样,但是我想要拦截的 RSS 提要没有我可以通过pathPattern 有效匹配的路径,我无法控制它。我尝试使用最初从 Google Reader APK 中提取的相同意图过滤器:

    <intent-filter android:label="@string/NewURL_intent_rss">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"/>
        <data android:host="*" />
        <data android:mimeType="text/xml"/>
        <data android:mimeType="application/rss+xml" />
        <data android:mimeType="application/atom+xml"/>
        <data android:mimeType="application/xml"/>
    </intent-filter>

但是当我通过单击 Chrome 中指向此类文件的链接来测试时,Chrome 只会浏览到该文件。我安装了谷歌阅读器,但也没有响应意图。如果我用与测试 URL 匹配的 pathPattern 替换 mimeType 行,我的应用程序会收到意图。通过向服务器发出 HEAD 请求,我验证了 URL 的 Content-Type 是作为“application/xml”发送的。测试设备是库存 ROM 上的 Nexus 10。

我通过恢复mimeType 过滤器并在shell 中从am start 启动URL 进行了另一项测试。此命令仅指定 URL,

am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d http://my.test/url

启动了浏览器,但是当我在此命令中明确指定类型时,

am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -t application/xml -d http://my.test/url

它向我展示了我的应用和 Google 阅读器的意图选择器。这似乎证实了过滤器正在生效,但是 Chrome 正在启动意图而不提供类型,并且意图解析器没有从 URL 中找到类型(它为content: URI 所做的方式),但似乎令人难以置信的是,这么多人可能会使用和推荐不可能工作的意图过滤器。有没有人有明确的答案:&lt;data android:scheme="http" android:mimeType="..." /&gt; 的意图过滤器有什么用?

【问题讨论】:

    标签: android mime-types intentfilter


    【解决方案1】:

    根据另一个 StackOverflow 答案,浏览器检查 Content-Disposition 标头,如果它指示附件,则甚至不检查意图过滤器。

    这可能是您面临的问题吗?

    https://stackoverflow.com/a/8770360/304876

    【讨论】:

    • 您链接到的答案是有人猜测这就是正在发生的事情。在这种情况下绝对不是:RSS 文件不带有 Content-Disposition: attachment 标头。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 2013-05-04
    • 1970-01-01
    • 2011-04-12
    • 2015-04-08
    • 2020-02-06
    • 2014-09-07
    相关资源
    最近更新 更多