1

I'm trying to run simple code to create a directory on the external storage picture directory. On 8.1.0 mkdirs keeps returning false and the directory is not created. On 7.1.1 it works just fine. Here's my code:

    private void initializePhotoStorageDirectory() {
    photoStorageDirectory = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            "FolderName");

    if (!photoStorageDirectory.exists()) {
        photoStorageDirectory.mkdirs();
    }
}

I declare the WRITE_EXTERNAL_STORAGE and I made sure the permission is granted during testing and, as I mentioned above, it's working on 7.1.1, so this doesn't looks like a permissions issue.

What am I doing wrong here?

Tako
  • 3,364
  • 2
  • 14
  • 21
  • Did you explicitly request the `WRITE_EXTERNAL_STORAGE` permission at runtime? https://stackoverflow.com/a/47788508 – Mike M. Feb 05 '18 at 23:43
  • Yap, I tried that too. Nothing different. – Tako Feb 05 '18 at 23:49
  • Ohhh, wait, I guess I didn't do it explicitly. I seems to be working now. Thanks! If you post it as an answer I'll approve. – Tako Feb 06 '18 at 18:20
  • Ah, cool. Actually, the answer here would be pretty much exactly the same, and the linked one is my answer, anyway, so I'll just mark this as a duplicate. Thanks, though. Glad you got it working. Cheers! – Mike M. Feb 06 '18 at 23:59

0 Answers0