Intent-filter abnormal behavior with samsung file browser

拜拜、爱过 提交于 2020-05-13 14:31:34

问题


I'm creating an intent filter for a specific extension (.infi) for my app. It works correctly with ES file explorer & Solid explorer. However when I open the file with Samsung default file explorer (Device Galaxy Tab S2) it shows a strange message "No application to perform this action", on other device (Note 4) it tries to open the file with Adobe Reader with an error message. Here is my code from manifests file :

<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:


For future references, I looked for another open source app implementing this feature correctly. These guys are doing a great job:

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

Here is my code that worked (just replace "infi" with your custom extention)

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


来源:https://stackoverflow.com/questions/39205640/intent-filter-abnormal-behavior-with-samsung-file-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!