【发布时间】:2013-05-03 18:55:12
【问题描述】:
有很多示例代码使用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? 的答案
我的具体用例是 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 所做的方式),但似乎令人难以置信的是,这么多人可能会使用和推荐不可能工作的意图过滤器。有没有人有明确的答案:<data android:scheme="http" android:mimeType="..." /> 的意图过滤器有什么用?
【问题讨论】:
标签: android mime-types intentfilter