我正在尝试将文件写入 Android 上的外部存储位置。这是我的代码:
String state = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(state)) {
saveState= true;
File pPath= Environment.getExternalStorageDirectory();
if(!pPath.exists()) {
boolean bReturn= pPath.mkdirs();
Log.d(TAG, "mkdirs returned: " + bReturn);
}
try {
File pFile= new File(pPath, "output.pcm");
pFile.createNewFile();
outputLocation= pFile.getAbsolutePath().toString();
} catch (IOException e) {
Log.d(TAG, "Could not create file: " + e.toString());
saveState= false;
}
} // end if we can read/write to the external storage
对 createNewFile() 的调用返回“无法创建文件:java.io.IOException:权限被拒绝”
我的清单文件中有 android.permission.WRITE_EXTERNAL_STORAGE 。关于这个问题似乎有很多问题,这解决了大部分问题,但我仍然有这个问题。这是清单的一部分:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="company.example.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<permission android:name="android.permission.RECORD_AUDIO"></permission>
<permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"></permission>
<permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></permission>
有任何想法吗?