Github user dblotsky commented on a diff in the pull request: https://github.com/apache/cordova-plugin-file/pull/170#discussion_r56600287 --- Diff: src/android/FileUtils.java --- @@ -433,28 +434,41 @@ public void run(JSONArray args) throws JSONException, IOException { else if (action.equals("getDirectory")) { threadhelper( new FileOp( ){ public void run(JSONArray args) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException { - String dirname=args.getString(0); - String path=args.getString(1); - JSONObject obj = getFile(dirname, path, args.optJSONObject(2), true); - callbackContext.success(obj); + String dirname = args.getString(0); + String path = args.getString(1); + String nativeURL = resolveLocalFileSystemURI(dirname).getString("nativeURL"); + boolean containsCreate = args.toString().contains("\"create\":true"); + + if(containsCreate && needPermission(nativeURL, WRITE)) { + getPermissionDir(WRITE); + } + else if(!containsCreate && needPermission(nativeURL, READ)) { + getPermissionDir(READ); + } + else { + JSONObject obj = getFile(dirname, path, args.optJSONObject(2), true); + callbackContext.success(obj); + } } }, rawArgs, callbackContext); } else if (action.equals("getFile")) { threadhelper( new FileOp( ){ public void run(JSONArray args) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException { - String dirname=args.getString(0); - /* - * If we don't have the package name in the path, we're reading and writing to places we need permission for - */ - if(dirname.contains(cordova.getActivity().getPackageName()) || - hasReadPermission()) { - String path = args.getString(1); - JSONObject obj = getFile(dirname, path, args.optJSONObject(2), false); - callbackContext.success(obj); + String dirname = args.getString(0); + String path = args.getString(1); + String nativeURL = resolveLocalFileSystemURI(dirname).getString("nativeURL"); + boolean containsCreate = args.toString().contains("\"create\":true"); + + if(containsCreate && needPermission(nativeURL, WRITE)) { + getPermissionFile(WRITE); + } + else if(!containsCreate && needPermission(nativeURL, READ)) { + getPermissionFile(READ); --- End diff -- This code is similar to the `WRITE` case, so it might be better to factor out them both into a function.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org For additional commands, e-mail: dev-h...@cordova.apache.org