有很多示例代码使用IntentFilter
,方案"http"
和mimeType
集合。查看答案Handling MIME type that is the result of a browser POST in Android,Intent filter for browsing XML (specifically rss) in android和How to open my Android app when rss link is opened in browser?MIME类型意图过滤器是否适用于HTTP URL?
具体使用情况而我是RSS链接,像那些过去的两个问题,但RSS提要我想拦截没有我可以pathPattern
有效匹配的路径,我无法控制。我已经使用最初是从谷歌阅读器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现在浏览该文件。我安装了Google阅读器,而且也没有响应意图。如果我将mimeType
行替换为与测试网址匹配的pathPattern
,我的应用将收到该意图。通过向服务器发送HEAD请求,我已验证URL的Content-Type是作为“application/xml”发送的。测试设备是ROM 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
这表明我的意图选择器我的应用程序和谷歌阅读器。这似乎证实过滤器正在生效,但Chrome在没有提供类型的情况下启动了意图,而意向解析器没有从URL中找到该类型(对于content:
URI的方式),但似乎并不合理这么多人可能会使用并推荐不可能工作的意图过滤器。有没有人有明确的答案:<data android:scheme="http" android:mimeType="..." />
有什么用意图过滤器?
您链接到的答案是有人**猜测**这就是发生了什么事。它肯定不是在这种情况下:RSS文件不附带“Content-Disposition:附件”标头。 – 2013-07-10 12:40:21