Question

I want to create a folder in SD card ,and i already add the permission

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

in manifest file.below is my code,but mkdirs return false! Can you help me!

File exportDir = new File(
                Environment.getExternalStorageDirectory().toString(), "happydiarybackup");
        if (!exportDir.exists()) {
            boolean a = exportDir.mkdirs();
            Log.d("mkdir ",exportDir.getAbsolutePath() + " make "+ a);
        }
Was it helpful?

Solution

Try this. It might help you.

String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/happydiarybackup/";
try
{
    File dir = new File(fullPath);
    if (!dir.exists()) {
      dir.mkdirs();
    }
}
 catch (Exception e) {
   Log.e("App", "Exception" + e.getMessage());
}

OTHER TIPS

1.Check your compileSdkVersion 2.Android: mkdirs()/mkdir() on external storage returns false. Make sure your put the permission tag in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top