【问题标题】:intent-filter to catch intents for viewing *.ext files意图过滤器来捕获查看 *.ext 文件的意图
【发布时间】:2015-01-16 10:26:54
【问题描述】:

我正在尝试找出我需要的意图过滤器,以便:

查看带有 *.npk 扩展名的文件或内容

我阅读了大量关于意图过滤器的 stackoverflow 文章,但仍然无法理解我缺少什么。

例如,当这是我的意图过滤器时,我希望它能够捕获带有“*.npk”扩展名的文件。我知道模式的错误,所以我添加了多条数据线以捕获 .npk 之前有 0-4 个点的路径:

        <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)}

我不明白为什么上面的过滤器没有捕捉到这个意图。我在总指挥官意图和 Dropbox 意图之间看到的唯一区别是标志,恕我直言,额外内容不应该产生影响,并且文件扩展名之前的路径中有 2 对 4 个点,但我的意图过滤器应该小心。

注意:我正在开发和测试棒棒糖,但我希望它可以在 api 9+ 上运行。

【问题讨论】:

    标签: android android-intent intentfilter file-extension


    【解决方案1】:

    经过长时间的反复试验,我发现以下解决方案有效。我必须将 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多