0

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

                }
            };
Tim
  • 35,413
  • 11
  • 95
  • 121
Niv
  • 59
  • 1
  • 4

1 Answers1

0

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.

Antrromet
  • 15,294
  • 10
  • 60
  • 75
  • Got the solution from [this link](http://stackoverflow.com/questions/6248887/android-device-specific-camera-path-issue) – Antrromet Apr 30 '12 at 09:49