android - Get path of DCIM folder on both primary and secondary storage -
android - Get path of DCIM folder on both primary and secondary storage -
i writing application should upload pictures taken photographic camera stored in dcim/camera folder on both internal memory , sd card.
this means before every upload available storages have checked presence of images.
i utilize environment.getexternalstoragepublicdirectory(environment.directory_dcim)
access primary storage, can either sd card or internal memory (depends on device).
from documentation: "note: don't confused word "external" here. directory can improve thought media/shared storage. filesystem can hold relatively big amount of info , 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."
my question is, how can access secondary storage check presence of images in dcim/camera folder without hard-coding path, not work since sd card might emulated in different path.
try file[] adirarray = contextcompat.getexternalfilesdirs(context, null);
see http://developer.android.com/reference/android/support/v4/content/contextcompat.html#getexternalfilesdirs(android.content.context, java.lang.string)
remember external storage (sd card) not emulated , paths visible users. above (if returns non null) returns root path (file) of each mounted external storage. if adirarray.length > 1, next gets dcim path looking on removable storage.
file aextdcimdir = new file(adirarray[1], environment.directory_dcim);
maybe in case, want check adirarray[0], adirarray[1], ... (all files returned in array) presence of environment.directory_dcim.
note environment.getexternalstoragepublicdirectory(environment.directory_dcim) returns same new file(adirarray[0], environment.directory_dcim).
android
Comments
Post a Comment