使用三星文件浏览器进行意图过滤异常行为

时间:2016-08-29 11:50:55

标签: android android-intent intentfilter

我正在为我的应用为特定扩展程序(.infi)创建一个intent过滤器。它适用于ES文件浏览器&坚实的探险家。但是当我用三星默认文件浏览器(设备Galaxy Tab S2)打开文件时,它会在其他设备上显示一条奇怪的消息“没有应用程序执行此操作”(注4)它尝试用Adobe Reader打开文件时出错信息。这是来自清单文件的代码:

<activity android:name=".ImportCollections">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file" />
            <data android:host="*" />
            <data android:mimeType="*/*" />
            <data android:pathPattern=".*\\.infi" />
        </intent-filter>

        <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="http" />
            <data android:host="*" />
            <data android:mimeType="*/*" />
            <data android:pathPattern=".*\\.infi" />
        </intent-filter>

        <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="content" />
            <data android:mimeType="application/octet-stream" />
            <data android:pathPattern=".*\\.infi" />
            <data android:host="gmail-ls" />
        </intent-filter>


    </activity>

1 个答案:

答案 0 :(得分:0)

为了将来的参考,我找了另一个正确实现此功能的开源应用程序。这些家伙做得很好:

https://github.com/ankidroid/Anki-Android/blob/develop/AnkiDroid/src/main/AndroidManifest.xml

这是我的代码有效(只需用您的自定义扩展替换“infi”)

<activity
        android:name=".ImportCollections"
        android:launchMode="singleTask"
        android:parentActivityName=".ManageCollections">
        <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=".*\\.infi"
                android:scheme="http" />
            <data
                android:host="*"
                android:mimeType="*/*"
                android:pathPattern=".*\\.infi"
                android:scheme="https" />
            <data
                android:host="*"
                android:mimeType="*/*"
                android:pathPattern=".*\\.infi"
                android:scheme="content" />
            <data
                android:host="*"
                android:mimeType="*/*"
                android:pathPattern=".*\\.infi"
                android:scheme="file" />
        </intent-filter>
        <!-- MIME type matcher for .infi files coming from providers like gmail which hide the file extension -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="application/infi" />
            <data android:mimeType="application/x-infi" />
            <data
                android:mimeType="application/octet-stream"
                android:scheme="content" />
            <data
                android:mimeType="application/zip"
                android:scheme="content" />
        </intent-filter>
    </activity>