1

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

arberg
  • 4,148
  • 4
  • 31
  • 39
  • No. It is not possible. – blackapps May 27 '21 at 16:32
  • And hard to believe that Total Commander could. Can you post a screenshot? – blackapps May 27 '21 at 16:48
  • `using the MediaShare Intent ` I do not know that intent. Can you elaborate? – blackapps May 27 '21 at 16:51
  • @blackapps: I've fixed the typo (I meant MediaStore) and clarified the intent. I can't show screenshot as I cannot recreate the pop-up without uninstalling the app and lose my data. Its easy, just install it on an Android-11, and navigate to `/Android/data/`. Thank you for the help and the info. How sure are you that it's impossible (ie. what's your background/reason for believing it)? – arberg May 27 '21 at 17:54
  • The same links that you posted. That's the reason. – javdromero May 27 '21 at 18:16
  • I wonder why you cannot navigate to Android/data and then post a screenshot for us. What does that have to do with a pop-up? And saf does not enter data dir either. It does not even show it. – blackapps May 27 '21 at 18:47
  • `(I meant MediaStore) and clarified the intent.` Well ACTION_OPEN_DOCUMENT_TREE is from Storage Access Framework and has nothing to do with the media store. – blackapps May 28 '21 at 06:01
  • And what you told about Total Commander does not come true. Navigating to the Android dir one sees indeed a data dir. But entering that dir one sees only packagename of Total Commander. Not of other apps. So that app does not have access either. Selecting (with saf) the Android dir for a user defined location does not show data directory which is normal. No... You posted wrong info here. – blackapps May 28 '21 at 06:25
  • Ty for clearing up my misunderstanding reg. MediaStore/SAM, and for installing TC to get to the bottom of this. No my TC claim is definitely true, see my screenshots, I just used it to copy all my kindle books out of the amazon kindle app for backup purposes. See my images (added at bottom of Q), don't you get an '-> Installed apps' entry? If not I assume its because that option only works if the app was already installed before upgrading OS, that would explain why even my attempts with legacy approach fail to access /Android/data/ – arberg May 28 '21 at 08:26
  • I just tested TC access of one of my own apps. After uninstalling and reinstalling that app from PlayStore, I could still see its /Android/data in TC (its cache files because I don't have any data in the files folder, but access-wise that should be the same, its still under /Android/data). I still havn't figured out how to do that with legacy approach, I know this question is about non-legacy, but I would trust the conclusion more if I could reproduce TC's way. I think I'll ask Ghisler how he did it. – arberg May 28 '21 at 08:40
  • I asked here, lets see if I get an answer even though its pretty off topic: https://www.ghisler.ch/board/viewtopic.php?f=22&t=74720 – arberg May 28 '21 at 08:48
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/232992/discussion-between-arberg-and-blackapps). – arberg May 28 '21 at 09:13
  • I had a look at your first screenshot and it is the same as i see too. One sees the data directory but upon entering there is only commanders own package. Further one sees a button for all packages which tells that removable micro sd card is write protected. But continuing one can select the data directory (with what looks like the gui for ACTION_OPEN_DOCUMENT_TREE) and miraculously all packages are displayed. Incredible. You were right. Hmm.. I have to think about this as why would it be possible for TC? Sorry for not believing you at word. – blackapps May 28 '21 at 09:26
  • Yes. It is possible using SAF and some manipulation. – blackapps May 28 '21 at 10:20

1 Answers1

3

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;
    }
blackapps
  • 8,011
  • 2
  • 11
  • 25
  • 1
    Seems to be working, I can get it to grant me access to '/Android/data' with startdir="Android%2Fdata", or equivalently Uri.encode("Android/data"). I'll play with it later (and accept it). It even seems to work without legacy flag. Awesome, but I'm really confused now as I though that was specifically not supported on Android-11 (for accessing Android/data this way). I'm probably just mixing up different notes. – arberg May 28 '21 at 13:04
  • Officially it is not supported. But if TC can do it then we do it too. And of course it works without legacy flag as that one was for Android 10 devices. I owe you that you did continue to talk about TC. – blackapps May 28 '21 at 15:01
  • Yeah, no problem, I'm glad you solved my problem, at least partially, the next part (for me) would be figuring out how SAF works, I found a nice GitHub sample in kotlin, which helps partially. After reading the changelist for Android-11 again, I suspect Google was targeting direct file access with their legacy-flag and limitations and the new managed permission. I seriously doubt they would miss this path-way to Android/data, if they wanted to remove it. It would have been nice if the change-list told that just use SAF for this, but sometimes its difficult to cover everything.... – arberg May 28 '21 at 16:20