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

半城伤御伤魂 提交于 2019-11-28 05:04:35

问题


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!


回答1:


<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>



回答2:


Give the

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

out side the < application > tag



来源:https://stackoverflow.com/questions/8387252/cant-create-a-folder-in-external-storage-on-android-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!