Search code examples
androiddirectorysandboxscoped-storageapp-folder

Access your own app's sandbox folder from a computer, when testing in Android 11+ emulators


When developing apps, I face often a problem of managing files in my own app private directory, under Android/data/com.package.name/... - to copy, create, edit, delete test files there. On Android 11 (possibly newer versions in the future) it is only possible on physical devices when connected with a USB cable. In emulators, it's utterly impossible to access that directory - adb shell or the mediocre "Device File Explorer" in Android studio, currently give me only "Permission denied" error, when trying to enter or list Android/data folder. Even on older versions of Android using adb shell or "Device File Explorer" is not convenient, and the device file explorer does not even list "hidden" files and folders (names starting with a dot), which I also need to manage.

What is the best solution to this problem? On older versions of Android I was using a WebDAV server app from Google Play, that lets me mount the entire storage of the emulator (or device) as a virtual directory or drive on my developer computer, but on Android 11 it cannot access my app's sandbox directory.


Solution

  • After using a 3rd party WebDAV server, I came to the conclusion that the only solution for Android 11+ is to embed a file server (WebDAV or similar) into my own app, at least in the DEBUG build.

    I cloned a very old GitHub WebDAV Server for Android project: https://github.com/erspicu/Baxermux.server.http, however there was so much to change, fix, enhance, that I finally created a new Android app project, copied code fragments from Baxermux and continued from there. You may see the result on GitHub, a very light WebDAV server library, that can be included with gradle's debugImplementation statement for the purpose of managing files in the app sandbox (or the entire Android storage if needed, too, minus other apps' sandbox folders under Android 11+):

    https://github.com/gregko/Mini-WebDAV-server-for-Android

    Now I can access the folders using any WebDAV client. On my Windows development host I use the excellent WebDrive product - it mounts the directory exported by the Mini WebDAV server as a Windows drive, and I can use the native Windows File Explorer, or command prompt, can view and edit the files as if they were local to my computer.