Skip to content
tezvyn:

Scoped Storage: Your App's Private File Cabinet

Source: developer.android.comMediumHow cards are made

Scoped Storage: Your App's Private File Cabinet

Scoped Storage gives your app a private file cabinet on external storage, not a key to the whole building. It's the default on modern Android for saving data or accessing media. The footgun: don't use direct file paths to shared files; you must use new.

Why it exists

To enhance user privacy and reduce file clutter. Previously, apps with storage permission could read any file on a user's device, creating security risks. Scoped Storage limits this broad access and ensures an app's files are cleaned up when the app is uninstalled.

The mental model

Think of Scoped Storage as giving each app its own locked file cabinet (an app-specific directory) instead of a master key to the entire office building (all of shared storage). To access a file from another cabinet, the app must ask a librarian (the OS, via an API like the Photo Picker) to retrieve it on the user's behalf.

How it works

By default, your app gets a private directory on external storage where it can read and write without any special permissions. To access files outside this sandbox, you must use specific, purpose-built APIs. For media files like photos and videos, you use the MediaStore API. To let the user select any type of file, you use the Storage Access Framework (SAF) or the modern Photo Picker. These APIs present a system UI to the user, who then grants your app temporary access to only the selected file(s).

When to use it

This is the standard and mandatory file access model for all apps targeting modern Android versions (API 29+). You use it for any operation involving external storage, whether saving app-generated content or accessing user-created media.

When not to use it

You cannot opt out of Scoped Storage on modern Android. The old "legacy storage" model is deprecated. The only exception is for apps whose core functionality is file management, like a file explorer. These apps can request a special permission, MANAGE_EXTERNAL_STORAGE, but it is subject to strict Google Play review.

One canonical example

A messaging app needs to let a user attach a photo. Instead of requesting broad storage permissions and building its own gallery, it launches the Android Photo Picker. The user sees a secure, system-provided interface to select photos. The app then receives a content URI for each selected photo, granting it temporary read access without ever seeing the rest of the user's files.

Interview question

Under Android's Scoped Storage, how does an app typically gain access to a user's shared media files, like photos?

  • a.By directly using the file path to the media file after obtaining storage permission.
  • b.By using system-provided APIs like the Photo Picker, which grant temporary access via a content URI.Correct
  • c.By requesting the MANAGE_EXTERNAL_STORAGE permission at runtime.
  • d.By storing a copy of the media file within the app's private directory.
Why?

Scoped Storage mandates the use of system-provided APIs like the Photo Picker or MediaStore to access shared media, granting temporary access via content URIs. Option A describes the deprecated legacy approach, while A is for specialized file manager apps, not typical applications.

Just read this? Test yourself on what you have been reading.

Read the original → developer.android.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.

See open roles