π·οΈ We are aware that working with a file system is a very important part of android development. Till the android version-10
, once the user gave permission to access the external storage, he could access any file on the device.
π·οΈ But most of the time we don't need the entire storage system to be accessed. Users mostly do some action on a file or a group of files and don't need access to the entire file system, due to this there was a concern of security and privacy of the user.
π·οΈ The scoped storage enhances the control of user privacy on the device.
π΅πππ πππππππ ππππππππππππππ ππ πππππππ ππππ
FileSystem
is a way of storing data indocuments
instead ofkey-value
mapping mechanism.- Using this mechanism, we can
fetch
,add
,delete
, and move it to a different location. - We use it to store large sizes of data like
images
,audio
,video
, and so on. - We can store the data here instead of
shared preferences
orlocal database
.
- We need to get access to the
root-file
orroot-directory
. - Once we have the access, we can add more children files within the accessed location.
- The file is created with a name using the stream
- Stream is a pipe that can
send data in one direction
, orreceive the data from the other direction
. - We have two types of streams an
input stream
and anoutput stream
.Input streams
---> Used for reading data from a file.Output streams
--> Used for writing data to a file.
- We get a reference to a file or directory, Then Using that obtained reference create an
input stream
or theoutput stream
. Then using the particular stream we modify or read the data.
ππ’πππ ππ ππππππππ ππ π°ππππππ
- Each application has a
private directory
. - Thus many applications have their own
individual private directories
- The private directory of one application is not visible to the other application.
- This is the easiest way of storing the data
- Permission is not required to store the data in the internal storage
- Everything else apart from the internal storage is considered as external storage.
- Permission is required for storing data in external storage.
- Once you store the data(ex:-image) in the external storage, all the apps can access this data.
- But all the images stored in external storage are tracked by the apps that created it.
- Say
application-1
creates one image in the external storage, and theapplication-2
cannot delete it directly, instead requires the permission of the user before deleting it.
πΏπππππππ ππππππππππ π πππ ππ‘ππππππ πππππππ
- Lot of applications need permission.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
- Basically anyone with the above permission can access the files from external storage. Describing more like say We build an app and we can access all the images stored in external storage using above permission
- But most of them do only simple things with it. One example of this is you want to access
photos
inexternal storage
, but you might not needpdf
,doc
etc. - They might not have needed to access the whole storage but earlier they could.
- The files are left in external storage sometimes and occupy space.
- Even though the application is un-installed still the files are left as it is in the external storage.
π·ππ ππππππ πππππππ ππ π ππππππππ ππ ππ‘ππππππ πππππππ ππππ πππππ
Scope storage was introduced to increase user privacy and give the end-user the decision making step to control their privacy
- Scoped storage was a solution to the problem.
- Scoped storage is optional in
android-10
but has become compulsory inandroid-11
. - Because of scoped storage, System knows which application has created which file and has a track of each file, Thus when an application is uninstalled all the files that it created are also un-installed.
- Every application has access to its
directory
inexternal storage
anddoes not need permission
.
πΌπππππ’πππ πππππ ππ ππ‘ππππππ πππππππ πππππππ ππππ πππππ ππππππππππππ?
- We can perform this action using
createWriteRequest
,createDeleteRequest
and modify the files in the directory created by other applications inexternal storage
- But the catch here is, that it requires the approval of the user.
- We can now
move the files to the trash
instead ofdeleting them
. - We can recover the items from the trash in a
30-days
life span.
πππππππ ππππππππππππ ππππ πππππππ ππππ ππππππππ
- Some of the applications that are just developed to handle the files themselves need access to the entire file system because that's the primary purpose of the application. How will that get handled is using special permission called.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
- If we add this permission, we do get access to the entire
file folder
. - But to add this to the play store, we need to follow a review process and approval from google justifying why this permission is required.
- After all the process, like any other permission, end users can disable the permission in the settings.
If you feel like support me a coffee for my efforts, I would greatly appreciate it.
Read contribution guidelines for more information regarding contribution.
Feature requests are always welcome, File an issue here.
Support it by clicking the β button on the upper right of this page. βοΈ
This project is licensed under the Apache License 2.0 - see the LICENSE file for details