Android 11 Scoped Storage | MediaStore API | Storage Access Framework

 Scoped Storage in Android 11

Recently my app got removed from the play store because I was targetting Android 11 with All-access storage permission, so here I am explaining to you how to access files without all-access permission in android 11.

What is Scoped Storage?

Scoped Storage allows you to access only the accessible Storage area of the whole storage
which is permissible by the user. By default, whole internal storage is not accessible except for the app package folder eg: android/data/com.android.app and this package folder is accessible but not visible to the user in android 11.

MediaStore API

MediaStore API allows you to access Image, Videos, Files
you can use it to get all Media present in the device to try it out I am adding  the Github link below 

https://github.com/ifahimkhan/AndroidStorage

For the explanation of the same, you can watch this youtube video.

https://www.youtube.com/watch?v=EeLz1DPMsW8

For MediaStore Files, you can refer to this Stackoverflow link where you can 
Create, Read, Write,  and Delete  open link



CAUTION: When you use the above method to access files in the download folder it will not work in android 11, because in the Android 11 download folder is restricted I can write the file in download but when trying to read it won't work.


Storage Access Framework (SAF)

When Using SAF below are the directory not accessible.
  1. The Download Directory
  2. The Android/data/
  3. The Android/obb/
How SAF works:-
you ask for the folder access permission to the user, hence the user allows it so now you can access all the files and nested directories inside that selected folder.

To try Storage Access Framework you can use the GitHub project 





That's it for this post,
Thank you for reading!










Comments

Popular posts from this blog

HOW TO GET FREE WEB HOSTING FOR WEBSITE BY FAHIM KHAN

Demystifying Java: Your Journey to Coding

Git Challenge V