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!