You must create a folder in the root of the SD card. Android API 21+.

The manifest spelled:

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

Code:

 private boolean isExistDir() { File dir = new File(Environment.getExternalStorageDirectory().getPath() + File.separator + "myDir"); if (dir.exists()) return true; if (dir.mkdirs()) return true; return false; } 

Check for SD (Returns true):

 public boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; } 

But when I call mkdirs() I get false. Folder is not created. How to create a folder?

    1 answer 1

    Found a solution completely by accident.

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

    Why did not guess before this immediately:

    Reason 1: Google 5-10 pieces of similar questions, everywhere it was advised to indicate only "WRITE_EXTERNAL_STORAG".

    Reason 2: I sincerely thought that write rights imply read rights. Those. if only READ is allowed, then WRITE is prohibited. But! If allowed by WRITE, then READ please.

    The question remains why it did not work without READ_EXTERNAL_STORAGE. But I think that this is a feature of API 21+.