ionic-frameworkcapacitorionic-nativeionic5cordova-plugin-file

this.file.listDir won't return folders under the externalRootDirectory on Android


I am trying to select directories of file:///storage/emulated/0/images/ with ionic-native/file but the Entry[] et return 0.
I tried different folders under externalRootDirectory but get the same 0 results. I think maybe the cordova-plugin-file issue with capacitor, ionic-native/file. Can anyone list the folders, files under Root?

I have 100+ files in images but the Entry[] et keep return 0 if I use this code.

let _app_EXT_Root_Dir = this.file.externalRootDirectory;
this.file.listDir(_app_EXT_Root_Dir,"images").then( et =>{
      console.log("List Dir: " + et.length); // --> always List Dir: 0
    });

I'm working with Ionic 5 - Capacitor 3 - Angular.
"@ionic-native/file": "^5.36.0"
"cordova-plugin-file": "^6.0.2"


Solution

  • I think I found a solution. The plugin works fine on Android 9 but not on Android 10.

    In Android 10, you have to add android:requestLegacyExternalStorage="true" to your config AndroidManifest.xml:

    <application 
        android:requestLegacyExternalStorage="true"