Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions src/android/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public class FileUtils extends CordovaPlugin {
public static final int GET_FILE_CALLBACK_CODE = 0;
public static final int WRITE_CALLBACK_CODE = 1;
public static final int GET_DIRECTORY_CALLBACK_CODE = 2;
public static final int WRITE = 3;
public static final int READ = 4;
public static final int GET_ENTRIES_CALLBACK_CODE = 3;
public static final int WRITE = 4;
public static final int READ = 5;

public static int UNKNOWN_ERR = 1000;

Expand Down Expand Up @@ -525,8 +526,19 @@ else if (action.equals("readEntries")) {
threadhelper( new FileOp( ){
public void run(JSONArray args) throws FileNotFoundException, JSONException, MalformedURLException {
String fname=args.getString(0);
JSONArray entries = readEntries(fname);
callbackContext.success(entries);
try {
String nativeUrl = resolveLocalFileSystemURI(fname).getString("nativeURL");
if(needPermission(nativeUrl, READ)) {
getPermissionEntries(READ);
}
else
{
JSONArray entries = readEntries(fname);
callbackContext.success(entries);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, rawArgs, callbackContext);
}
Expand All @@ -547,6 +559,15 @@ public void run(JSONArray args) throws FileNotFoundException, JSONException, Mal
return true;
}

private void getPermissionEntries(int permissionType) {
if(permissionType == READ) {
PermissionHelper.requestPermission(this, GET_ENTRIES_CALLBACK_CODE, Manifest.permission.READ_EXTERNAL_STORAGE);
}
else {
PermissionHelper.requestPermission(this, GET_ENTRIES_CALLBACK_CODE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
}

private void getPermissionFile(int permissionType) {
if(permissionType == READ) {
PermissionHelper.requestPermission(this, GET_FILE_CALLBACK_CODE, Manifest.permission.READ_EXTERNAL_STORAGE);
Expand Down Expand Up @@ -1181,7 +1202,16 @@ public void run(JSONArray args) throws FileExistsException, IOException, TypeMis
callback.success(obj);
}
}, lastRawArgs, callback);
break;
break;
case GET_ENTRIES_CALLBACK_CODE:
threadhelper( new FileOp( ){
public void run(JSONArray args) throws FileNotFoundException, JSONException, MalformedURLException {
String fname=args.getString(0);
JSONArray entries = readEntries(fname);
callback.success(entries);
}
}, lastRawArgs, callback);
break;
case WRITE_CALLBACK_CODE:
threadhelper( new FileOp( ){
public void run(JSONArray args) throws JSONException, FileNotFoundException, IOException, NoModificationAllowedException {
Expand Down