How to properly create folder and files on /storage/emulated/0 using Cordova File Plugin?

I try to use Cordova File to create folder MyApp (if not exist) and files on /storage/emulated/0 (internal storage)

The code is like

 await this.file.checkDir(this.file.externalRootDirectory, "MyApp").then(
      async value => {
        if (!value) {
          await this.file.createDir(this.file.externalRootDirectory, "MyApp", true).catch(err => console.error('error in createDir', err));
        }
      },
      async err => {
        console.error("error in checkDir", err);
        await this.file.createDir(this.file.externalRootDirectory, "MyApp", true).catch(err => console.error('error in createDir', err));
      }
 );

However, the console just outputs

error in checkDir > FileError {code: 1, message: "NOT_FOUND_ERR"}
error in createDir > FileError {code: 12, message: "PATH_EXISTS_ERR"}

When I log the value of externalRootDirectory, the console shows

file:////storage/emulated/0/

How can I properly access this path and create folder?

Thank you.

Ionic info

Ionic:

   Ionic CLI                     : 6.13.1
   Ionic Framework               : @ionic/angular 5.6.1
   @angular-devkit/build-angular : 0.1102.5
   @angular-devkit/schematics    : 11.2.5
   @angular/cli                  : 11.2.5
   @ionic/angular-toolkit        : 3.1.1

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 12 other plugins)
1 Like

same error here , did you solve?

I am facing the same issue in SAMSUNG device with Android 10 and some other devices. Is there any solution of this?

1 Like

Adding below configuration in config.xml resolves the issue.

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
  <application android:requestLegacyExternalStorage="true" />
</edit-config>