【发布时间】:2013-03-15 14:12:58
【问题描述】:
问题:
如何让我的应用程序无条件地打开文件和 url 扩展名?
设置我的intent-filter 我已经束手无策了,因为这没有任何意义。我的最终目标是打开任何以某个扩展名结尾的path。举个例子,让我们选择 ".riley" 作为我的目标扩展。
我的基础`intent-filter`
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.riley" />
</intent-filter>
目前可以从file 和content 打开。
问题 #1:路径模式
对于初学者来说,data 参数 pathPattern 似乎并没有像我设置的那样做任何事情:
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.riley" />
.. 但我仍然可以在 file 和 content 方案下使用不以 ".riley" 结尾的 Uri 路径打开 Intents。
我的应用程序使用此 intent-filter 打开的几个示例路径是:
Path: /storage/sdcard0/Download/MyApp.apk
Path: /messagesByAccount/1
为了清楚起见,“路径:”只是我自己在日志中添加的。第一个来自file 方案下的gmail,第二个来自content 方案下的gtalk。鉴于此,我已经对 intent-filters 的工作方式感到困惑。
pathPattern 在 file 和 content 方案中被忽略。
问题 #2:在浏览器中打开
我试图让我的应用程序从浏览器打开 ".riley" 扩展,但是重定向链接没有 MIME 类型,所以我从data 模式(我之前有 android:mimeType="*/*",因为 MIME 类型不一致),这让我可以很好地从重定向 URL 中打开。
当我尝试从浏览器(例如:http://thisisnotarealdomainname.com/myfile.riley)打开直接 ".riley" URL 并且从我的应用程序打开的选项消失时,问题出现了。将mimeType 值添加回我的data 模式允许我从直接URL 打开。
intent-filter 不允许我打开直接和间接 URL。
问题 #3:方案
我希望能够从多种不同的方案类型中打开(例如:http,file,content), but as soon as I removeschemealtogether, it disqualifies my application from opening thehttpscheme and when I specifyscheme="*", it disqualifies my application from opening ANY scheme. I've also tried adding moredata`模式,但我感觉好像只有一个生效,因为这对我一点帮助都没有。
因此,指定http 将允许http,但显然不允许file 或content,并且不指定scheme 将禁用http。
我无法从所有不同的方案中打开。
重申一下,考虑到这些并发症,我如何才能让我的应用程序无条件地打开文件和 url 扩展名?
【问题讨论】:
标签: android android-intent mime-types intentfilter