我正在尝试找出我需要的intent-filters以便:
使用* .npk扩展程序查看文件或内容
我阅读了有关intent-filters的stackoverflow文章的大量内容,但仍然无法理解我缺少的内容。
例如,当这是我的intent-filter时,我希望它能够捕获扩展名为“* .npk”的文件。我知道模式的错误,所以我添加了多条数据线,以便捕获之前有0-4点的路径.npk:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:pathPattern=".*\\.npk" />
<data android:scheme="file" android:pathPattern=".*\\..*\\.npk" />
<data android:scheme="file" android:pathPattern=".*\\..*\\..*\\.npk" />
<data android:scheme="file" android:pathPattern=".*\\..*\\..*\\..*\\.npk" />
<data android:scheme="file" android:pathPattern=".*\\..*\\..*\\..*\\..*\\.npk" />
</intent-filter>
当我从总指挥官应用程序中打开一个文件时,它可以工作,并按预期启动我的活动(顺便说一下,即使我只有一个pathPattern =“。* \\。npk”,这也行,所以可能修复了提到的错误在棒棒糖中):
{act=android.intent.action.VIEW dat=file:///storage/emulated/0/Android/data/com.fletech.smartbaby.android.pro/files/npk/animal-water-he.npk typ=application/octet-stream flg=0x10000000 cmp=com.fletech.smartbaby.android/.CategorySliderActivity}
但是我无法使用Dropbox应用程序。这是来自logcat的“捕获”意图。为了捕获它我添加了android:mimeType =“* / *”所以我可以选择我的应用程序,现在每个文件(也是.jpg)想要打开我的应用程序。
{act=android.intent.action.VIEW dat=file:///storage/emulated/0/Android/data/com.dropbox.android/files/u123456/scratch/apk/nature_0.npk typ=application/octet-stream flg=0x10000003 cmp=com.fletech.smartbaby.android/.CategorySliderActivity (has extras)}
我不明白为什么上面的过滤器没有抓住这个意图。我看到总指挥官意图和保护箱意图之间的唯一区别是标志,额外的东西,这应该没有区别恕我直言,并且在文件扩展名之前的路径中有2对4点,但我的意图过滤器应该小心它的。
注意:我正在开发和测试棒棒糖,但我希望它能用于api 9 +。
答案 0 :(得分:0)
经过长时间的反复试验后,我发现以下解决方案正常运行。我不得不将android:host =“*”和android:mimeType =“* / *”添加到数据元素中。似乎官方的android文档中存在一些不一致的地方。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.npk" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\.npk" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\.npk" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\.npk" />
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\..*\\..*\\..*\\..*\\.npk" />
</intent-filter>