MaterialFilePicker icon indicating copy to clipboard operation
MaterialFilePicker copied to clipboard

Library doesn't showing types other than images on Android 11 (like pdf, doc)

Open Bharatsingh-nickelfox opened this issue 4 years ago • 2 comments

Bharatsingh-nickelfox avatar Feb 16 '21 13:02 Bharatsingh-nickelfox

Did you find any solution for this problem ? I want to filter and show only pdfs. I tried another library, but that also has some issues.

pradeep-orbi avatar May 14 '21 15:05 pradeep-orbi

Hi there, The library was working properly before upgrading to android R (API 30)... Now it does see nothing but the images. I have found a solution for this. You have to add this permission check somewhere in your code:

if (isAndroid11ReadFilesPermissionRequired())
                askForAndroid11ReadFilesPermission()

where

private fun isAndroid11ReadFilesPermissionRequired() =
        SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()

@RequiresApi(Build.VERSION_CODES.R)
private fun askForAndroid11ReadFilesPermission() {
    try {
        val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
        intent.addCategory("android.intent.category.DEFAULT");
        intent.data =
            Uri.parse(String.format("package:%s", getApplicationContext().packageName));
        startActivityForResult(intent, FILE_PICKER_ANDROID11_REQUEST_CODE);
    } catch (e: Exception) {
        myTimber(e)
        val intent = Intent()
        intent.action = Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION
        startActivityForResult(intent, FILE_PICKER_ANDROID11_REQUEST_CODE)
    }
}

Also, I have added this to AndroidManefist.xml:

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
    tools:ignore="ScopedStorage" />

MuhammadSulaiman001 avatar Sep 14 '21 18:09 MuhammadSulaiman001