Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 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 Reply

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...