title: Capacitor Filesystem returns error while using main functions
body: <p>I created a new app using capacitor 3, in this app I used the <a href="https://capacitorjs.com/docs/apis/filesystem" rel="nofollow noreferrer">Filesystem</a> to perform some functions. I created a service to handle everything related to the filesystem, but when I went to use the functions I had some problems.</p>
  <p>When using Android 11 to create a directory using the <code>mkdir()</code> function I get the following error:</p>
  <blockquote>
  <p><code>Unable to create directory, unknow reason.</code></p>
  </blockquote>
  <p>Also on Android 11, when I try to create a file using only <code>writeFile()</code> it returns the following error:</p>
  <blockquote>
  <p><code>FILE_NOTCREATED</code></p>
  </blockquote>
  <p>For Android 10 and below the <code>mkdir()</code> function works correctly, but the <code>writeFile()</code> function causes the app to crash without any errors. Also, if I try to change the <code>Diretory.ExternalStorage</code> to <code>Diretory.External</code> I can create a directory in Android 11, but it still crashes when writing a file.</p>
  <p>Using Android 11, I tried to write a <code>txt</code> file with a simple string and with also with a small base64 string. When using <code>Diretory.External</code> I can write the base64 string in a new file, but when using the <code>Diretory.ExternalStorage</code> I got the <code>FILE_NOTCREATED</code> error.</p>
  <p>I did all the configurations and followed the steps in the documentation to set up <code>AndroidManifest.xml</code>.</p>
  <p>Several tests have been done on emulators and phones with different versions of Android.</p>
  <p><strong>Tests with <code>writeFile()</code></strong></p>
  <pre><code>Android 11
  base64 + Diretory.External = success
  string + Diretory.External = crash
  base64 + Diretory.ExternalStorage = error
  string + ExternalStorage  = error
  
  Android 10 and below
  base64 + Diretory.External = success
  string + Diretory.External = crash
  base64 + Diretory.ExternalStorage = success
  string + ExternalStorage  = crash
  </code></pre>
  <hr />
  <p><strong>Android XML</strong></p>
  <pre><code>    &lt;application 
        android:allowBackup=&quot;true&quot; 
        android:icon=&quot;@mipmap/ic_launcher&quot; 
        android:label=&quot;@string/app_name&quot; 
        android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
        android:supportsRtl=&quot;true&quot; 
        android:theme=&quot;@style/AppTheme&quot; 
        android:requestLegacyExternalStorage=&quot;true&quot;
      &gt;
  
      &lt;!-- Permissions --&gt;
  
      &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.MANAGE_EXTERNAL_STORAGE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
      &lt;uses-feature android:name=&quot;android.hardware.location.gps&quot; android:required=&quot;true&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
  </code></pre>
  <p><strong>MainFunction.ts</strong></p>
  <pre><code>testeFilesystem(): void {
      let path: string = 'test/project';
      this.filesystem.checkAndCreateDir(path).then(_ =&gt; {
          this.filesystem.writeFile(path, 'test.txt', 'test').then(_ =&gt; {
              this.uicontroller.presentToast('file saved');
          });
      })
  }
  </code></pre>
  <p><strong>FilesystemService.ts</strong></p>
  <pre><code>checkAndCreateDir(path: string): Promise&lt;boolean&gt; {
    return Filesystem.readdir({
      path: path,
      directory: Directory.ExternalStorage
    }).then(_ =&gt; {
      return true;
    }).catch(_ =&gt; {
      return Filesystem.mkdir({
        path: path,
        directory: Directory.ExternalStorage,
        recursive: true
      }).then(_ =&gt; {
        return true;
      });
    });
  }
  
  writeFile(path: string, filename: string, content: string): Promise&lt;boolean&gt; {
    return Filesystem.writeFile({
      path: path + filename,
      data: content,
      directory: Directory.ExternalStorage
    }).then(result =&gt; {
      if (result) {
        return true;
      } else {
        return false;
      }
    });
  }
  </code></pre>
  <p><strong>Ionic Info</strong></p>
  <pre><code>Ionic CLI                     : 6.16.1 C:\Users\User\AppData\Roaming\npm\node_modules@ionic\cli
    Ionic Framework               : @ionic/angular 5.6.7
    @angular-devkit/build-angular : 0.1102.10
    @angular-devkit/schematics    : 11.2.13
    @angular/cli                  : 11.2.13
    @ionic/angular-toolkit        : 3.1.1
  
  Capacitor:
    Capacitor CLI      : 3.0.0
    @capacitor/android : 3.0.0
    @capacitor/core    : 3.0.0
    @capacitor/ios     : not installed
  
  Utility:
    cordova-res : 0.15.3
    native-run  : 1.3.0
  
  System:
    NodeJS : v14.16.1 (C:\Program Files (x86)\nodejs\node.exe)
    npm    : 6.14.12
    OS     : Windows 10
  </code></pre>