MIME类型意图过滤器适用于HTTP URL吗?

3
有很多示例代码使用带有方案“http”和设置了“mimeType”的IntentFilter。请参阅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链接,就像最后两个问题一样,但我无法使用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只是浏览到该文件。我已经安装了Google Reader,但它也没有响应此意图。如果我使用与测试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 Reader使用。这似乎确认了过滤器正在生效,但是Chrome启动意图时没有提供类型,并且意图解析器无法从URL中找到类型(就像对于content: URI一样),但是似乎很难想象有那么多人在使用并推荐不可能起作用的意图过滤器。有没有人有明确的答案:带有<data android:scheme="http" android:mimeType="..." /> 的意图过滤器有什么用处?

1个回答

0

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

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

https://dev59.com/fF_Va4cB1Zd3GeqPOwDg#8770360


你链接到的答案只是一个人在猜测发生了什么。但在这种情况下肯定不是这样的:RSS文件没有带有Content-Disposition: attachment头部。 - Dan Hulme

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接