Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
763 views
in Technique[技术] by (71.8m points)

can't create a folder in external storage on android device

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...