Scoped Storage Example

Updated 11 October 2021

Save

Scoped storage was a feature introduced in Android Q(10). This is now mandatory from Android 11 that all apps targeting this version have scoped storage implemented, these new improvements have privacy in mind.
In preview versions of android before Android 10, the runtime permission to read or write was required to access almost every file on disk, the Scoped storage feature is introduced mainly to avoid this situation. You can also check the official documentation:  Click Here

Manage device storage

From Android 11, the apps can use the scoped storage model can access only their own app-specific cache files.
If your app needs to manage device storage check the below action to free the space.

1. Check for free space by invoking the ACTION_MANAGE_STORAGE intent action.
2. If there isn’t enough free space on the device, prompt the user to give your app consent to clear all caches.
To do so, invoke the ACTION_CLEAR_APP_CACHE intent action(It might affect device battery life and might remove a large number of files from the device.).

 

 

Let’s write a sample code to access storage.

AndroidManifest.xml for permission:

 

ConstantHelpers.kt:

 

MainActivity.kt:

activity_main.xml:

string.xml:

dimens.xml:

 

. . . . . . . . .

That’s it from my side for today, thanks for reading it until now. You can check our other android blogs Click Here.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home