Android getAbsolutePath() not returning full path

∥☆過路亽.° 提交于 2019-12-02 12:31:16

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/21237007/android-getabsolutepath-not-returning-full-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!