This article really helped me.
https://ourcodeworld.com/articles/read/1559/how-does-manage-external-storage-permission-work-in-android
1. Request MANAGE_EXTERNAL_STORAGE permission :
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ourcodeworld.plugins.capacitornativefilepicker"
xmlns:tools="http://schemas.android.com/tools"
>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage"/>
</manifest>
2. Request External Storage Permissions
After declaring the permissions, you need to request the regular READ_EXTERNAL_STORAGE
and WRITE_EXTERNAL_STORAGE
permissions. Note that we don't include the MANAGE_EXTERNAL_STORAGE
, because if you request it, when verifying if you have access or not, the mentioned permission will always return denied, even though the user has already granted access:
ActivityCompat.requestPermissions(
this,
new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.MANAGE_EXTERNAL_STORAGE
},
1
);
3. Checking permission of MANAGE_EXTERNAL_STORAGE
Now, instead of the regular permissions request to handle the mentioned permission, you need instead to verify whether the access to the external storage is allowed. In case it isn't, you need to launch a new activity showing the system's dialog where the user should manually allow the access to the external storage to your app like this:
import android.os.Environment;
import android.content.Intent;
import android.provider.Settings;
import android.net.Uri;
// If you have access to the external storage, do whatever you need
if (Environment.isExternalStorageManager()){
// If you don't have access, launch a new activity to show the user the system's dialog
// to allow access to the external storage
}else{
Intent intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Uri uri = Uri.fromParts("package", this.getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
So when the user installs the app and try to access the file picker, if the access to all files isn't granted yet, the following system intent will be launched:

The user will have to explicitly allow access to all files if you want to read files from any source in the device and that should be enough.