I would like to read Android/data so I can extract documents for backup purposes. Android 11 has changes that prohibit/limit this, but is it still possible? I don't want to use the legacy-approach (if possible).
According to this Manage all files on a storage device which talks about the MANAGE_EXTERNAL_STORAGE
permission it seems Google claims it should now be impossible (at least with this method):
Apps that are granted this permission still cannot access the app-specific directories that belong to other apps because these directories appear as subdirectories of Android/data/ on a storage volume.
https://developer.android.com/training/data-storage/manage-all-files https://developer.android.com/about/versions/11/privacy/storage#other-apps-data
Here storage#other-apps-data Google also says that apps can no longer access other apps Android/data
Access to app-specific directories on external storage On Android 11, apps can no longer access files in any other app's dedicated, app-specific directory within external storage.
Here on stackoveflow Thoryia shows us how to ask for the permission.
But can we use it (or any other method) to read those forbidden other app-data folders, Android/data/* ?
The Android app 'Total Commander' does it (on Android 11), and it seems to be using the StorageAccessFramework Intent Intent.ACTION_OPEN_DOCUMENT_TREE
to access the files (a guess based on the gui that pops up), but I havn't managed to figure out how to get that working either. Its possible Total Commander use a legacy-approach.
Pr request I've screenshots of Total Comander (TC) here on my OneDrive.
I strongly suspect TC just uses the target-29 access method, I found a list of its permissions here but cannot find which version it targets: Aptoide: TC v3.21
Your question has the same solution as when you had asked
"How can i let ACTION_OPEN_DOCUMENT_TREE open in a predifined directory?".
Well for that i had already a solution.
Tried it for DCIM and Android and such but never for Android/data.
But that works too!
You can use it not with classic file means but only with Storage Access Framework.
We will manupilate INITIAL_URI obtained from StorageManager..getPrimaryStorageVolume().createOpenDocumentTreeIntent().
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q)
{
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
Intent intent = sm.getPrimaryStorageVolume().createOpenDocumentTreeIntent();
//String startDir = "Android";
//String startDir = "Download"; // Not choosable on an Android 11 device
//String startDir = "DCIM";
//String startDir = "DCIM/Camera"; // replace "/", "%2F"
//String startDir = "DCIM%2FCamera";
// String startDir = "Documents";
String startDir = "Android/data";
Uri uri = intent.getParcelableExtra("android.provider.extra.INITIAL_URI");
String scheme = uri.toString();
Log.d(TAG, "INITIAL_URI scheme: " + scheme);
scheme = scheme.replace("/root/", "/document/");
startDir = startDir.replace("/", "%2F");
scheme += "%3A" + startDir;
uri = Uri.parse(scheme);
intent.putExtra("android.provider.extra.INITIAL_URI", uri);
Log.d(TAG, "uri: " + uri.toString());
((Activity) context).startActivityForResult(intent, REQUEST_ACTION_OPEN_DOCUMENT_TREE);
return;
}