Android Storage & Scoped Storage. Part-1 File storage basics
文章推薦指數: 80 %
If internal storage doesn't provide enough space to store app-specific files, android provides external storage for an app to access its directories.
GetstartedOpeninappKalaiselvanSigninGetstarted32FollowersAboutGetstartedOpeninappAndroidStorage&ScopedStoragePart-1FilestoragebasicsKalaiselvanJun19,2020·3minreadOverviewAndroidisbringinginlotofimprovementsinaccessingthedevicestorageforRead/Writeoperations.It’sallstartedwhenitintroducedruntimePermissions,whereanappmustaskforuser’spermissionsforaccessinganykindofsharedstoragedatainthedevice.Fromthenonandroidimposeslotofstrictmeasuresinaccessingthedatafromthedeviceonlyiftheappreallyneedsthosedataforperformingitswork.Storageinandroidsystemisclassifiedasfollows:App-specificstorageSharedstoragePreferencesDatabaseTounderstandthereasonforintroducingscopedstorageinandroid,weneedtohavesomebasicunderstandingofhowmediafilesanddocumentsareaccessed,editedorstoredintheinternalorexternalstoragebyanappandthepermissionsprovidedtotheappforaccessingthesharedfilesinthedevice.ApplicationStorageAppstoragecanbeclassifiedinto:InternalStorage(Filessavedhereareprotectedandaccessibleonlytotheappwhichcreated/storedit)ExternalStorage(Sometimesthisisapartofandroiddevicestorage,SDcards,etc.,)Fileswhicharestoredininternalstoragecannotbeaccessedbytheotherapplications.Onlytheappwhichcreatedthosefilescanaccessit.Thisprovidesoneformofsecurityforanapptostoreitssensitivefiles.Filesthatwerestoredinexternalstorageareaccessibletootherappsaswellprovidedthoseappshavedeclaredproperstoragepermissions.Althoughit’spossibleforotherappstoaccessthosefiles,thefilesstoredinthesedirectoriesaremeantforuseonlybytheparticularapp.Ifanappwantstostoresfilesinexternalstoragewhereothersappsshouldaccessthosefilesfortheiroperationthenthosefilesshouldbestoredinthesharedstorage.OneexampleforthisparticularusecaseisCameraapplication.Filescreated/editedbythecameraappshouldbeaccessibletoGalleryapp,Filemanagerapp,etc.,App-specificdirectoriesinInternalStorageAndroidOSprovidesconsiderableamountofspaceininternalstoragefortheapptoaccessitsdirectories.Usuallythesedirectoriescanbecalledfromacontextobject,Apppersistentdirectoryvalfile=File(context.filesDir,filename)2.AppcachedirectoryvalcacheFile=File(context.cacheDir,filename)App-specificdirectoriesinExternalStorageIfinternalstoragedoesn’tprovideenoughspacetostoreapp-specificfiles,androidprovidesexternalstorageforanapptoaccessitsdirectories.Likeinternalstorageappspecificdirectories,thesedirectoriescanalsobecalledfromacontextobject,Apppersistentdirectoryvalfile=File(context.filesDir,filename)2.AppcachedirectoryvalcacheFile=File(context.cacheDir,filename)ChoosingStoragelocationSometimes,adevicethatallocatesapartitionofitsinternalmemoryasanexternalstoragemightalsoprovidesanSDcardslot.Thismakesthedevicestohaveaprovisionforholdingmultiplestoragevolumes.Hencetoaccessdifferentstoragevolumes,wehavetocallthisparticularfunction,valexternalStorageVolumes:Array
延伸文章資訊
- 1Access app-specific files | Android Developers
If internal storage doesn't provide enough space to store app-specific files, consider using exte...
- 2Manage all files on a storage device | Android Developers
A PendingIntent , if the app with the specified package name has defined a custom "manage space" ...
- 3Storage Model | Android 101 - ProAndroidDev
Internal storage works as expected. Apps can access their app-specific directory without any rest...
- 4Switching to app-specific storage - SurveyCTO Documentation
In Admin Settings, there is a new option at the bottom labeled App storage location. You can swit...
- 5App specific storage - 軟體兄弟
App specific storage,Your app doesn't require any system permissions to read and write to files i...