我正在尝试在外部存储中创建一个文件夹,我在这里跟着其他几个线程。然而,即使我似乎正在做他们所表明的事情,创作也会失败。
这是一段代码
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();
当我执行它时,我明白了:
mExternalStorageAvailable = true;
mExternalStorageWriteable = true;
success = false;
这是整个清单文件:
<?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>
我做错了什么?谢谢!
答案 0 :(得分: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>
答案 1 :(得分:1)
给出
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在外面&lt;申请&gt;标签