Android - how to show (or select) files using a special extension when calling the "file selector" using Intent.ACTION_GET_CONTENT

I know that you can limit the available file types that appear in the file explorer caused by Intent.ACTION_GET_CONTENT easily using setType () , but this can only work for well-known file extensions such as .jpg, .pdf, .docx, which I need should show only files with a custom extension , for example .abc, so the user can only select a file that ends with .abc. I searched for a long time and still can not find an effective way to solve this problem; the closest one is to create a custom mime type, for example:

             <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:scheme="file" />
                <data android:mimeType="application/customtype" />
                <data android:pathPattern=".*\\.abc" />
                <data android:host="*" />
            </intent-filter>
            <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:scheme="content" />
                <data android:mimeType="application/customtype" />
                <data android:pathPattern=".*\\.abc" />
                <data android:host="*" />
            </intent-filter>

and use

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/customtype"); 
startActivityForResult(intent,FILE_SELECTOR_REQUEST_CODE);

, , :( , !

+4
1

android: mimeType = "application/customtype" , android: mimeType = "*/*" . mime, . , OS .

+2

Source: https://habr.com/ru/post/1683062/


All Articles