diff --git a/CHANGELOG.md b/CHANGELOG.md index 139b16d1..6df144c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo #### Unreleased +### 25-11-2024 +- Android: Fix endless loop of notification permission denial when granting exact alarm permission + #### Version 0.9.13 (07.10.2024) ### 07-10-2024 - Android: Deliver notifications while app is in foreground if `foreground` option is `true`. [RMET-3699](https://outsystemsrd.atlassian.net/browse/RMET-3699) diff --git a/src/android/LocalNotification.java b/src/android/LocalNotification.java index 197acd65..7cece77b 100644 --- a/src/android/LocalNotification.java +++ b/src/android/LocalNotification.java @@ -115,12 +115,10 @@ public void onResume (boolean multitasking) { super.onResume(multitasking); deviceready(); - if(!requestingNotificationsPermissions && requestingExactAlarmPermission) { + if(requestingExactAlarmPermission) { requestingExactAlarmPermission = false; onScheduleExactAlarmPermissionResult(); } - - requestingNotificationsPermissions = false; } /** @@ -172,7 +170,7 @@ public void run() { actions(args, command); } else if (action.equals("schedule")) { - schedule(args, command); + schedule(args, command, true); } else if (action.equals("update")) { update(args, command); @@ -235,8 +233,9 @@ private void launch(CallbackContext command) { @Override public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { super.onRequestPermissionResult(requestCode, permissions, grantResults); - if(requestCode == NOTIFICATION_PERMISSION_CODE){ - schedule(notificationArguments, callbackContext); + if (requestCode == NOTIFICATION_PERMISSION_CODE) { + schedule(notificationArguments, callbackContext, false); + requestingNotificationsPermissions = false; } } @@ -306,20 +305,23 @@ private void actions (JSONArray args, CallbackContext command) { * @param toasts The notifications to schedule. * @param command The callback context used when calling back into * JavaScript. + * @param requestExactAlarmPermission whether should request exact alarm permission or not + * (e.g. send false if already checked prior) */ - private void schedule (JSONArray toasts, CallbackContext command) { + private void schedule (JSONArray toasts, CallbackContext command, boolean requestExactAlarmPermission) { callbackContext = command; notificationArguments = toasts; - if(Build.VERSION.SDK_INT >= 33 - && !PermissionHelper.hasPermission(this, NOTIFICATION_PERMISSION) - && !requestingNotificationsPermissions){ + if(hasAnyExactNotification() && !getNotMgr().canScheduleExactAlarms() && requestExactAlarmPermission) { + requestScheduleExactAlarmPermission(); + } + else if(Build.VERSION.SDK_INT >= 33 + && !PermissionHelper.hasPermission(this, NOTIFICATION_PERMISSION) + && !requestingNotificationsPermissions + ){ requestingNotificationsPermissions = true; PermissionHelper.requestPermission(this, NOTIFICATION_PERMISSION_CODE, NOTIFICATION_PERMISSION); } - else if(hasAnyExactNotification() && !getNotMgr().canScheduleExactAlarms()) { - requestScheduleExactAlarmPermission(); - } else { scheduleWithPermission(); } @@ -423,7 +425,7 @@ private void onScheduleExactAlarmPermissionResult() { warning = OSLCNOWarning.EXACT_PERMISSION; } - schedule(notificationArguments, callbackContext); + schedule(notificationArguments, callbackContext, false); } /**