Skip to content

Commit

Permalink
feat(android): Add handlePermissions function for plugins to call (#3768
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jcesarmobile authored Nov 5, 2020
1 parent 65cef53 commit 3a7e282
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions android/capacitor/src/main/java/com/getcapacitor/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,20 @@ protected void onRequestPermissionsResult(int requestCode, String[] permissions,
return;
}

this.handlePermissions(permissions, grantResults);

savedCall.resolve(getPermissionStates());
savedCall.release(bridge);
}

/**
* Plugin overriding onRequestPermissionsResult should call this method to
* handle the permission status correctly
*
* @param permissions
* @param grantResults
*/
public void handlePermissions(String[] permissions, int[] grantResults) {
SharedPreferences prefs = getContext().getSharedPreferences(PERMISSION_PREFS, Activity.MODE_PRIVATE);

if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Expand Down Expand Up @@ -588,9 +602,6 @@ protected void onRequestPermissionsResult(int requestCode, String[] permissions,
editor.apply();
}
}

savedCall.resolve(getPermissionStates());
savedCall.release(bridge);
}

/**
Expand Down

0 comments on commit 3a7e282

Please sign in to comment.