Question

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

Était-ce utile?

La solution

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().

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top