title: Android: Permission denied when creating a new file in external storage
body: <p>I am trying to write a file to the external storage location on Android. Here is my code :</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The call to createNewFile() returns  "Could not create file: java.io.IOException: Permission denied"</p>
  
  <p>I have the android.permission.WRITE_EXTERNAL_STORAGE in my manifest file. There seems to be a ton of questions about this problem, and this solved most of them, but I am still having this issue. Here is part of the manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="company.example.sample"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="10" /&gt;
      &lt;permission android:name="android.permission.RECORD_AUDIO"&gt;&lt;/permission&gt;
      &lt;permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"&gt;&lt;/permission&gt;
      &lt;permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"&gt;&lt;/permission&gt;
  </code></pre>
  
  <p>Any ideas?</p>