How to obtain Request All files access on Android 11

7.5k Views Asked by At

Im investigating the File access changes associated with Android 11

I've configured an AVD fro Android R and created a Test Application that has the following Manifest contents

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.my.application">

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

I then create this Intent and start Activity expecting to see the Allow access to manage all files. in System Settings

    val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
    val uri = Uri.fromParts("package", packageName, null)
    intent.data = uri
    startActivity(intent)

However the user is presented with the App Info screen for my test application.

If I search in settings I can find the Apps & Notifications -> Special App Access -> All files access -> My test app is listed

Is this the process users have to follow to grant this permission?

Why doesnt using the Intent I constructed take the User directly to the All Files Access page?

2

There are 2 best solutions below

0
On BEST ANSWER

Implementing an intent for

  Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION 

will give your app read/write access for all files even on removable micro sd card.

0
On
if (SDK_INT >= Build.VERSION_CODES.R) {
        if (!Environment.isExternalStorageManager()) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
            Uri uri = Uri.fromParts("package", getPackageName(), null);
            intent.setData(uri);
            startActivity(intent);
        }
    } else {
        //below android 11=======
        startActivity(new Intent(this, ActivityPicture.class));
        ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE}, 100);
    }

Also add this to manifest :

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