Scoped Storage Tutorial for Android 11: Deep Dive

Scoped storage is mandatory for all apps targeting Android 11. In this tutorial, you’ll learn how to implement the latest storage APIs in Android 11 by adding features to a meme-generating app. By Carlos Mota.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Limitations

Although you’ll get broader access to the file system with these solutions, there will still be limitations on what your app can access. App-specific storage is sensitive, and for that reason, access to the app’s internal and external files is unavailable. There’s no possibility to grant read/write access over them.

There’s often a feature in file explorers that allows you to check the disk usage and free up space by clearing other apps’ caches. Scoped storage doesn’t allow this to be done in the app. Instead, you need to call:

fun openNativeFileExplorer(activity: AppCompatActivity) {
  val intent = Intent(StorageManager.ACTION_MANAGE_STORAGE)
  activity.startActivity(intent)
}

This launches the native files application. Then call:

fun clearAppsCacheFiles(activity: AppCompatActivity) {
  val intent = Intent(StorageManager.ACTION_CLEAR_APP_CACHE)
  activity.startActivity(intent)
}

This frees up disk space.

Where to Go From Here?

Download the completed project files by clicking the Download Materials button at the top or bottom of the tutorial.

Congratulations! You completed this tutorial. You learned how to take advantage of scoped storage in Android 11 and you improved your app experience!

Now that you’ve mastered scoped storage, why not dive deeper into Android by exploring some of its other features? For instance, the Bubbles tutorial might be a fun challenge. Or consider learning about augmented reality apps in ARCore with Kotlin!

We hope you enjoyed this tutorial. If you have any questions or comments, please join the forum discussion below!