有很多示例代码使用带有方案“http”和设置了“mimeType”的
但是当我在Chrome中点击指向这种文件的链接进行测试时,Chrome只是浏览到该文件。我已经安装了Google Reader,但它也没有响应此意图。如果我使用与测试URL匹配的
启动了浏览器,但当我在此命令中明确指定类型时,出现了以下情况:
IntentFilter
。请参阅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链接,就像最后两个问题一样,但我无法使用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="..." />
的意图过滤器有什么用处?
Content-Disposition: attachment
头部。 - Dan Hulme