@@ -88,6 +88,7 @@ public class FileUtils extends CordovaPlugin {
8888 public static final int ACTION_GET_FILE = 0 ;
8989 public static final int ACTION_WRITE = 1 ;
9090 public static final int ACTION_GET_DIRECTORY = 2 ;
91+ public static final int ACTION_READ_ENTRIES = 3 ;
9192
9293 public static final int WRITE = 3 ;
9394 public static final int READ = 4 ;
@@ -285,6 +286,7 @@ public boolean execute(String action, final String rawArgs, final CallbackContex
285286 if (action .equals ("testSaveLocationExists" )) {
286287 threadhelper (new FileOp () {
287288 public void run (JSONArray args ) {
289+
288290 boolean b = DirectoryManager .testSaveLocationExists ();
289291 callbackContext .sendPluginResult (new PluginResult (PluginResult .Status .OK , b ));
290292 }
@@ -543,10 +545,16 @@ public void run(JSONArray args) throws JSONException, NoModificationAllowedExcep
543545 }
544546 else if (action .equals ("readEntries" )) {
545547 threadhelper ( new FileOp ( ){
546- public void run (JSONArray args ) throws FileNotFoundException , JSONException , MalformedURLException {
547- String fname =args .getString (0 );
548- JSONArray entries = readEntries (fname );
549- callbackContext .success (entries );
548+ public void run (JSONArray args ) throws FileNotFoundException , JSONException , MalformedURLException , IOException {
549+ String directory = args .getString (0 );
550+ String nativeURL = resolveLocalFileSystemURI (directory ).getString ("nativeURL" );
551+ if (needPermission (nativeURL , READ )) {
552+ getReadPermission (rawArgs , ACTION_READ_ENTRIES , callbackContext );
553+ }
554+ else {
555+ JSONArray entries = readEntries (directory );
556+ callbackContext .success (entries );
557+ }
550558 }
551559 }, rawArgs , callbackContext );
552560 }
@@ -1236,6 +1244,15 @@ public void run(JSONArray args) throws JSONException, FileNotFoundException, IOE
12361244 }
12371245 }, req .getRawArgs (), req .getCallbackContext ());
12381246 break ;
1247+ case ACTION_READ_ENTRIES :
1248+ threadhelper ( new FileOp ( ){
1249+ public void run (JSONArray args ) throws FileNotFoundException , JSONException , MalformedURLException {
1250+ String fname =args .getString (0 );
1251+ JSONArray entries = readEntries (fname );
1252+ req .getCallbackContext ().success (entries );
1253+ }
1254+ }, req .getRawArgs (), req .getCallbackContext ());
1255+ break ;
12391256 }
12401257 } else {
12411258 LOG .d (LOG_TAG , "Received permission callback for unknown request code" );
0 commit comments