Quantcast
Channel: WRITE_EXTERNAL_STORAGE not working on lollipop even though it's set in the manifest - Stack Overflow
Viewing all articles
Browse latest Browse all 5

WRITE_EXTERNAL_STORAGE not working on lollipop even though it's set in the manifest

$
0
0

I'm trying to save images from the apps local data folders to external storage. My manifest contains the following (before the manifest's application tags):

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>

When I try the following

try {        InputStream in = new FileInputStream(filePath);        File outPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);        File outFile = new File(outPath, "mypicture.jpg");        //try fails at this line        OutputStream out = new FileOutputStream(outFile);        byte[] buf = new byte[1024];        int len;        while ((len = in.read(buf)) > 0) {            out.write(buf, 0, len);        }        in.close();        in = null;        out.flush();        out.close();        out = null;} catch (IOException e) {    e.printStackTrace();}

I get this error:

java.io.FileNotFoundException: /storage/emulated/0/Pictures/mypicture.jpg: open failed: EACCES (Permission denied)

I've also tried a slightly different output path instead:

 String sdCardPath = Environment.getExternalStorageDirectory() +"/MyFolder"; new File(sdCardPath).mkdirs(); File outFile = new File(sdCardPath, "mypicture.jpg");

but that gives me an error too:

java.io.FileNotFoundException: /storage/emulated/0/MyFolder/mypicture.jpg: open failed: ENOENT (No such file or directory)

The device is running Android 4.4.2, so shouldn't need to request permissions at runtime (as far as I'm aware it can't request them).

Is there something else that could be missing in order to allow saving a file to external storage?


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images