0
我已閱讀了很多帖子,但仍然沒有答案。在添加WRITE_EXTERNAL_STORAGE後,檢查sd卡是否可寫入和掛載,我仍然得到「文件的父目錄不可寫入」。我正在使用eclipse和模擬器並將SdkVersion設置爲「7」。爲什麼我會得到「文件的父目錄不可寫?」
我該如何寫入SD卡?
示例代碼如下:
<uses-premission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
.
.
.
checkSDStatus();
.
.
.
File sdCardRoot = Environment.getExternalStorageDirectory();
// Check state of SD card
String sdState = Environment.getExternalStorageState();
Log.d("--- state ---", sdState);
File dir = new File (sdCardRoot.getAbsolutePath() + "/download");
dir.mkdirs();
File file = new File(dir, fileName);
.
.
.
private void checkSDStatus(){
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
mExternalStorageAvailable = mExternalStorageWriteable = true;
Log.d("-- sd card --", "-- card writable --");
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
Log.d("-- sd card --", "-- card read only --");
} else {
mExternalStorageAvailable = mExternalStorageWriteable = false;
Log.d("-- sd card --", "-- card unvailable --");
}
}