From 3a7e282a7515784dd343bbf1e3d52e0299bac887 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Thu, 5 Nov 2020 19:28:52 +0100 Subject: [PATCH] feat(android): Add handlePermissions function for plugins to call (#3768) --- .../src/main/java/com/getcapacitor/Plugin.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/Plugin.java b/android/capacitor/src/main/java/com/getcapacitor/Plugin.java index f0b23784ff..cfedd0d179 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Plugin.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Plugin.java @@ -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) { @@ -588,9 +602,6 @@ protected void onRequestPermissionsResult(int requestCode, String[] permissions, editor.apply(); } } - - savedCall.resolve(getPermissionStates()); - savedCall.release(bridge); } /**