In my app I have hard-coded a path to captured camera images. However this do not work for all devices, because the storage path for images is different for different devices. Is there a way to dynamically get this path which will be valid for all devices?
This is what I have tried:
if (externalStorageState.equals(Environment.MEDIA_MOUNTED)
|| externalStorageState.equals(Environment.MEDIA_UNMOUNTED)
|| externalStorageState
.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
File path = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM
+ "/Camera");//////////----path of captured images
Log.d("operator", " path: " + path);
if (path.exists()) {
if (path.isDirectory()) {
fo = new FileObserver(path.toString(),
FileObserver.CLOSE_WRITE) {
@Override
public void onEvent(int event, String path) {
SimpleDateFormat sdfDateT = new SimpleDateFormat(
"yy-MM-dd HH:mm:ss", Locale.US);
String st = sdfDateT.format(System
.currentTimeMillis());
Log.d("operator", "in event");
Log.d("operator", "lat: " + lat + " " + "lng: "
+ lng + " " + "location: " + addre + " " + "time: " + st);
ptd.insert(st, String.valueOf(lat), String.valueOf(lng), addre);
}
};