问题:
如何让我的应用程序无条件打开文件和 URL 扩展名?
我对设置我的intent-filter
因为这些都没有任何意义。我的最终目标是开放任何有path
以某个扩展结尾。为了举例,我们选择".riley"作为我的目标延伸。
我的基地“意图过滤器”
<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
and content
.
问题#1:路径模式
对于初学者来说,似乎并不data
范围pathPattern
做任何事情,正如我所设定的:
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.riley" />
..但我仍然可以打开Intent
s with Uri
不以以下结尾的路径".riley"在下面file
and content
scheme.
我的应用程序使用此打开的几个示例路径intent-filter
are:
Path: /storage/sdcard0/Download/MyApp.apk
Path: /messagesByAccount/1
为了清楚起见,“路径:”只是我自己在日志中添加的内容。第一个是来自 gmail 下的file
方案,第二个来自 gtalk 下的content
方案。鉴于此,我已经很困惑如何intent-filters
work.
The pathPattern
被忽略file
and content
计划。
问题#2:在浏览器中打开
我尝试打开我的应用程序".riley"来自浏览器的扩展,但是重定向链接没有 MIME 类型,所以我删除了mimeType
值来自于data
模式(我有android:mimeType="*/*"
之前,因为 MIME 类型不一致),这使我可以从重定向 URL 中打开。
当我尝试直接打开一个时出现问题".riley"来自浏览器的 URL(例如:http://thisisnotarealdomainname.com/myfile.riley)并且从我的应用程序打开的选项消失了。添加mimeType
价值回到我的data
模式允许我从直接 URL 打开。
The intent-filter
不允许我打开直接和间接 URL。
问题#3:方案
我希望能够从多种不同的方案类型中打开(例如:http,
file,
content), but as soon as I remove
schemealtogether, it disqualifies my application from opening the
httpscheme and when I specify
方案=“*”, it disqualifies my application from opening ANY scheme. I've also tried adding more
data` 模式,但我感觉好像只有一个生效,因为这对我没有任何帮助。
所以,指定http
将允许http
,但显然也不允许file
or content
并且没有指定scheme
禁用http
.
我无法从所有不同的方案中打开。
重申一下,如何让我的应用程序无条件打开文件和 url 扩展名,鉴于这些并发症?