2

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>

何か案は?

4

1 に答える 1