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
延伸文章資訊
- 1Android: App Data & Files || Apps Internal Storage - YouTube
DescriptionThis video talks about How to store data in app specific storage directory.If you face...
- 2Switching to app-specific storage - SurveyCTO Documentation
In Admin Settings, there is a new option at the bottom labeled App storage location. You can swit...
- 3Internal or External storage for editable app-specific file
Internal storage is best when you want to be sure that neither the user nor other apps can access...
- 4App specific storage - 軟體兄弟
App specific storage,Your app doesn't require any system permissions to read and write to files i...
- 5Android Storage & Scoped Storage. Part-1 File storage basics
If internal storage doesn't provide enough space to store app-specific files, android provides ex...