The path provided by getExternalStoragePublicDirectory does not work on Android 5.0

I want to save the image in the device’s photo catalog. I use

path = Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES);

After calling this method on my S3 (Android 4.3), the path contains "/ storage / emulated / 0 / Pictures". When I try to create a file in this directory, it works. I use

File.createTempFile(
            imageFileName, ".jpg", path);

for this. I tested on the Galaxy S5 and on the emulator, as with Android 5.0. In the emulator, the path contains "/ storage / sdcard / Pictures". When I try to create a file in it, I get "java.io.IOException: open failed: ENOENT (There is no such file or directory)". My emulator supports SD card. S5 does not have an SD card. Perhaps this is the cause of the problem on the device. I use the permission WRITE_EXTERNAL_STORAGE in my manifest. I even tried using file.mkdirs () to ensure that the path exists. But this also does not work.

+4
source share
1 answer

Finally I found a solution: In my AndroidManifest.xml, I used:

  <uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="18"/>

due to this info in doku :

, Android 4.4 (API 19), , WRITE_EXTERNAL_STORAGE , ( getExternalFilesDir()). API 18 .

, , , , API > 19. , .

+1

All Articles