Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android mkdirs in SD card return false.help me, it spends me 3days

Tags:

android

mkdirs

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);
        }
like image 563
user1951072 Avatar asked Oct 22 '22 20:10

user1951072


2 Answers

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());
}
like image 89
Ajay S Avatar answered Oct 29 '22 19:10

Ajay S


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

like image 32
FiShboneL Avatar answered Oct 29 '22 18:10

FiShboneL