1

I create a file and save an image to it using the following code:

private File createImageFile() throws IOException {
        String timeStamp = new SimpleDateFormat("yyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = getActivity().getApplicationContext().getFilesDir();
        File image = File.createTempFile(imageFileName, ".jpg", storageDir);
        return image;

    }

When I use image.getAbsolutePath();, I get somwthing like this:

/data/data/co.za.package.app/files/filename.jpg

The actual path of the image is:

/storage/sdcard0/Android/data/co.za.package.app/files/filename.jpg

Why is getAbsolutePath() returning the wrong path? I hardcoded the above String and my image displayed fine. Do any of you have any idea what I'm doing wrong? Thank you in advance

Lunchbox
  • 1,538
  • 2
  • 16
  • 42

1 Answers1

3

The actual path of the image is

You may have a file there, but that is not the File that you are setting up in the code. Try getExternalFilesDir(null) instead of getFilesDir().

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hi, thanks for the reply, but I want to save to image in the app internal directory and then retrieve it afterwards. – Lunchbox Jan 21 '14 at 06:08