5

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);
        }
user1951072
  • 65
  • 1
  • 6

2 Answers2

2

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());
}
Ajay S
  • 48,003
  • 27
  • 91
  • 111
  • Thank you !now it is working.I just put the permission at the first of the manifest file,I don`t know why ,but it`s worked! – user1951072 Jan 06 '13 at 05:48
1

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

Community
  • 1
  • 1
FiShboneL
  • 21
  • 4