title: Android APIv29 FileNotFoundException EACCES (Permission denied)
body: <p>I'm not able to access storage when building for targetSdkVersion v29.</p>
  
  <p>Here is my gradle configuration:</p>
  
  <pre><code>    compileSdkVersion 29
      buildToolsVersion "29.0.2"
      ...
          minSdkVersion 15
          targetSdkVersion 29
  </code></pre>
  
  <p>NOTE that <code>WRITE_EXTERNAL_STORAGE</code> permission is granted and the same setup works fine when building for <code>targetSdkVersion 28</code>.</p>
  
  <p>Here is my implementation:</p>
  
  <pre><code>        val outputFolder = File(baseFolder + File.separator + "Output Folder")
          if (!outputFolder.exists()) {
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
                  Files.createDirectory(outputFolder.toPath()) //This allways returns false with targetSdkVersion 29
              } else {
                  if (!outputFolder.mkdirs()) {
                      Log.e("SaveRaw", "Unable to create folder for audio recording")
                  }
              }
          }
  
          outputFile = File("$baseFolder/Output Folder/$filename")
          try {
              fileOutputStream = FileOutputStream(outputFile)
          } catch (e: FileNotFoundException) {
              e.printStackTrace() // allways throwing exception here, even if Output Folder exists 
          }
  </code></pre>
  
  <p>and here is the exception:</p>
  
  <pre><code>W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Chirp Auto Tester/2019_10_17 10:44:43.raw: open failed: EACCES (Permission denied)
  W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:496)
          at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:235)
          at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:186)
  </code></pre>
  
  <p>Hope anyone has an answer, what am I missing here? </p>
  
  <p>Update: </p>
  
  <p>Here is where <code>baseFolder</code> comes from. Note that <code>getExternalStorageDirectory</code> is a deprecated method.</p>
  
  <pre><code>        val baseFolder: String = if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
              Environment.getExternalStorageDirectory().absolutePath
          } else {
              context.filesDir.absolutePath
          }
  </code></pre>
  
  <p>Thanks</p>