3

I am trying to create a folder in external storage and I followed a couple of other threads here. However, even though I seem to be doing what they indicate, creation fails.

Here's a piece of code

boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;

    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        mExternalStorageAvailable = false;
        mExternalStorageWriteable = false;
    }
    File exst = Environment.getExternalStorageDirectory();
    String exstPath = exst.getPath();

    File fooo = new File(exstPath+"/fooo");
    boolean success = fooo.mkdir();

When I execute it, I get this:

mExternalStorageAvailable = true;
mExternalStorageWriteable = true;
success = false;

Here's the entire manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mydev.mobile.Test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <activity
        android:label="@string/app_name"
        android:name=".TestIndexSearchForHitsAndroidActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

What am I doing wrong? Thanks!

I Z
  • 5,719
  • 19
  • 53
  • 100

2 Answers2

4
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mydev.mobile.Test"
android:versionCode="1"
android:versionName="1.0" >
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
....
</manifest>
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
confucius
  • 13,127
  • 10
  • 47
  • 66
  • Namari, thanks much it worked! But can you explain to me why it did not work before? In some examples that I used, they had the `WRITE_EXTERNAL_STORAGE` line under `` and I think they claimed it worked. – I Z Dec 05 '11 at 15:21
1

Give the

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

out side the < application > tag

Padma Kumar
  • 19,893
  • 17
  • 73
  • 130