Android 10 & 11 storage cheat sheet

Petros Douvantzis
3 min readMar 4, 2021

Google keeps changing the way apps can access shared files by adding and lifting restrictions to existing APIs to the point they had to write this.

The following is a simplified guide about the storage options of an app and how they differentiate between Android versions.

TLDR: not much have actually changed if you’re making a camera app. If you have a gallery or file app, then you have to do some refactoring.

In Android, an app has access to:

  1. private folders that only the app can see: getFilesDir(), getCacheDir() .
    /data/user/0/<package_name>/files
    /data/user/0/c<package_name>/files
  2. app-specific folders that other apps can see. There is a generic one: getExternalFilesDirs() and a media one: getExternalMediaDirs(). These are deleted when the app is deleted. These directories have 2 variants:
    1. those that exist in internal storage. You can get the path using the first element in the array returned by the aforementioned methods. /storage/emulated/0/Android/data/<package_name>/files
    /storage/emulated/0/Android/media/<package_name>

    2. those that exist in external storage such as SD card. You can get the path using the second element in the array returned by the aforementioned methods.
    /storage/11EC-2402/Android/data/<package_name>/files
    /storage/11EC-2402/Android/media/<package_name>
  3. public folders that all apps can see, like DCIM, Music, Download folder etc. They can be selected by the user by starting an ACTION_OPEN_DOCUMENT_TREE intent. These directories have 2 variants:
    1. those that exist in internal storage. Another (deprecated) way to get the path to these folders is with getExternalStoragePublicDirectory().
    /storage/emulated/0/DCIM
    /storage/emulated/0/Download
    2. those that exist in external storage such as SD card.
    /storage/11EC-2402/DCIM

Note that the paths above are examples and should not be used as is.

All Android versions can write to 1, 2.1, 2.2 using the classic Files API.

Android 10 requires asking user permission for WRITE_EXTERNAL_STORAGE, as usual, and setting android:requestLegacyExternalStorage=”true” to the manifest to access 3.1 using Files API. You can write whatever filetype you want in these folders and also delete pre-existing files or files created by other apps. 3.2 can’t be accessed this way.

Android 11 can write to 3.1 and 3.2 (no manifest flag needed) as long as the file type written matches the directory. For example, you can’t write a .mp3 file in DCIM folder. In Downloads folder, you can write whatever you want. Your app can delete only files created by it. It can’t delete pre-existing files or file created by a previous installation of the app. It can read files created by other apps. You can’t write to a random folder in the internal storage such as /storage/emulated/0/Test but you can read its contents.

Note that in Android 11 you don’t even have to declare WRITE_EXTERNAL_STORAGE in your manifest or ask user permission in order to write to all the aforementioned folders. If you want to read files created by other apps though, you’ll have to ask the user for WRITE_EXTERNAL_STORAGE or READ_EXTERNAL_STORAGE permission.

And here’s another small cheat sheet taken from here:
Android 11 == code R == API 30
Android 10 == code Q == API 29

--

--