Skip to content
Permalink
Browse files
CB-11142: Fix the NeedPermission code for the case when external medi…
…a is not mounted in Android

 This closes #179
  • Loading branch information
Raghav Katyal committed Apr 26, 2016
1 parent 5caa768 commit e9cc506ef3215054895b0441197f85baf7ed5046
Showing 2 changed files with 13 additions and 1 deletion.
@@ -279,6 +279,14 @@ Listing asset directories is really slow on Android. You can speed it up though,
adding `src/android/build-extras.gradle` to the root of your android project (also
requires cordova-android@4.0.0 or greater).

### Permisson to write to external storage when it's not mounted on Marshmallow

Marshmallow requires the apps to ask for permissions when reading/writing to external locations. By
[default](http://developer.android.com/guide/topics/data/data-storage.html#filesExternal), your app has permission to write to
`cordova.file.applicationStorageDirectory` and `cordova.file.externalApplicationStorageDirectory`, and the plugin doesn't request permission
for these two directories unless external storage is not mounted. However due to a limitation, when external storage is not mounted, it would ask for
permission to write to `cordova.file.externalApplicationStorageDirectory`.

## iOS Quirks

- `cordova.file.applicationStorageDirectory` is read-only; attempting to store
@@ -569,7 +569,11 @@ private boolean hasWritePermission() {

private boolean needPermission(String nativeURL, int permissionType) throws JSONException {
JSONObject j = requestAllPaths();
String[] allowedStorageDirectories = {j.getString("applicationStorageDirectory"), j.getString("externalApplicationStorageDirectory")};
ArrayList<String> allowedStorageDirectories = new ArrayList<String>();
allowedStorageDirectories.add(j.getString("applicationStorageDirectory"));
if(j.has("externalApplicationStorageDirectory")) {
allowedStorageDirectories.add(j.getString("externalApplicationStorageDirectory"));
}

if(permissionType == READ && hasReadPermission()) {
return false;

0 comments on commit e9cc506

Please sign in to comment.