Store file in android -
i want store file in android. following flow:-
if(sd card available){ //store in sd card... }else{ //if sd card not available... //store in phone memory.. }
the question there way access sd card , internal memory paths?
i understand
contextwrapper cw = new contextwrapper(getapplicationcontext()); file destinationdirforchequeimageininternalmemory = cw.getdir("dirname", context.mode_private);
always gives internal storage location.
is guaranteed storage location in phone memory?
environment.getexternalstoragedirectory()
does above line give sd card path? if not return? there way sd card location? (if environment.getexternalstoragedirectory returns phone memory path inspite of device having sd card in it.)
please throw insight how this?
just read android documentation on it.
https://developer.android.com/reference/android/os/environment.html#getexternalstoragedirectory()
getexternalstoragedirectory
added in api level 1 file getexternalstoragedirectory () return primary shared/external storage directory. directory may not accessible if has been mounted user on computer, has been removed device, or other problem has happened. can determine current state getexternalstoragestate().
note: don't confused word "external" here. directory can better thought media/shared storage. filesystem can hold relatively large amount of data , shared across applications (does not enforce permissions). traditionally sd card, may implemented built-in storage in device distinct protected internal storage , can mounted filesystem on computer.
on devices multiple users (as described usermanager), each user has own isolated shared storage. applications have access shared storage user they're running as.
in devices multiple shared/external storage directories, directory represents primary storage user interact with. access secondary storage available through getexternalfilesdirs(string), getexternalcachedirs(), , getexternalmediadirs().
applications should not directly use top-level directory, in order avoid polluting user's root namespace. files private application should placed in directory returned context.getexternalfilesdir, system take care of deleting if application uninstalled. other shared files should placed in 1 of directories returned getexternalstoragepublicdirectory(string).
writing path requires write_external_storage permission, , starting in kitkat, read access requires read_external_storage permission, automatically granted if hold write permission.
starting in kitkat, if application needs store internal data, consider using getexternalfilesdir(string), getexternalcachedir(), or getexternalmediadirs(), require no permissions read or write.
this path may change between platform versions, applications should persist relative paths.
Comments
Post a Comment