Scoped storage

Data and storage Mid-level Kotlin 2.0+ API 29+ Reviewed By Best Latest Apps

Pick the fix

An app exports a CSV and wants the user to choose the folder. What's right under scoped storage?

Options
Hint 1 of 1

Who should choose the location?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Launch ACTION_CREATE_DOCUMENT and write to the returned URI

Correct. The user picks a location; no storage permission is needed.

Why not the others?
  • B Request MANAGE_EXTERNAL_STORAGE and write to /sdcard. Play restricts that permission to apps that need full file access.
  • C Write to getExternalFilesDir(). That's app-specific and removed on uninstall; users rarely find it.
  • D Write to filesDir. That's private to the app.

30-second answer

Since Android 10, and enforced from Android 11, apps get unrestricted access only to their own app-specific directories. Shared media goes through MediaStore: your app can add photos, video and audio without permission, and reading others' media needs READ_MEDIA_* on Android 13+. For other documents, use the Storage Access Framework, where the user picks files. Broad storage permissions are restricted on Play.

Practise saying it · 35 s. No recording, just a timer

Explain scoped storage.

Say your answer out loud, then check which of these points you covered:

  • App-specific directories need no permission
  • MediaStore for shared media
  • Storage Access Framework for documents
  • Photo picker for picking

Deep dive

App-specific files: filesDir and cacheDir (internal) or getExternalFilesDir(); deleted on uninstall.

The photo picker avoids media permissions entirely for picking images.

MANAGE_EXTERNAL_STORAGE is for file managers and similar apps only.

Use ACTION_CREATE_DOCUMENT to let the user choose where to export a file.

Common mistakes

  • Requesting MANAGE_EXTERNAL_STORAGE for an ordinary app.
  • Writing files to the root of external storage.
  • Asking for READ_MEDIA_IMAGES just to pick one photo.

Senior take & follow-ups

Know the three paths: app-specific, MediaStore, Storage Access Framework.

Follow-up questions

Think of your answer first, then open the hint.

  1. Where should a cache go?

    Show hint

    cacheDir, which the system may clear.

  2. How do you export a CSV the user can find?

    Show hint

    ACTION_CREATE_DOCUMENT or MediaStore Downloads.

Similar on iOS: Reading and writing files iOS apps live in a sandbox too, with a document picker for user files.

Suggest a fix if something here is wrong or out of date.