Q:

Fetching captured images path dynamically in services in android

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);

                }
            };

A:

Use getExternalStorageDirectory() if API level is below 7 and then append /Pictures to get the path of Photos storage.
for API level > 7 use getExternalStoragePublicDirectory (DIRECTORY_PICTURES).
Also you can have a look at this link.

