MHM MHM - 2 years ago 265
Android Question

Android: mkdir() returns false

I'm driven crazy with this:

Log.d("STATE", Environment.getExternalStorageState());
File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "work_data");
Log.d("PATH", f.getAbsolutePath());
if (!f.exists()) {
Log.d("MAKE DIR", f.mkdirs() + "");

The output log is like this:

STATE mounted
PATH /mnt/sdcard/DCIM/work_data
MAKE DIR false

I even have added permission:

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

But I don't know why it could not create the folder. I also used
step by step but result is the same. Please help me. I have googled so much but none of them helps me. I spent at least 2 day on this stupid thing. Thanks for your help!!


Sorry everyone! I had added
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
tag. this was my mistake! But thank you all for reply.

Answer Source

I have had the same problem and I have searched everything for a week trying to find the answer. I think I found it and I think it's ridiculously easy, you have to put the uses-permission statement in the right place...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

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

When I had it inside the <application></application> section it did not work. If this helps, please mark it as answered and vote me up. Thanks!!!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download