Skip to content

Commit

Permalink
Merge pull request #35 from OutSystems/fix/android/notification-permi…
Browse files Browse the repository at this point in the history
…ssion-denial

Fix ::: Android ::: Denying notification permission while grating exact alarms
  • Loading branch information
OS-pedrogustavobilro authored Dec 3, 2024
2 parents 9a841ea + cd67010 commit 5122e8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 16 additions & 14 deletions src/android/LocalNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,10 @@ public void onResume (boolean multitasking) {
super.onResume(multitasking);
deviceready();

if(!requestingNotificationsPermissions && requestingExactAlarmPermission) {
if(requestingExactAlarmPermission) {
requestingExactAlarmPermission = false;
onScheduleExactAlarmPermissionResult();
}

requestingNotificationsPermissions = false;
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -423,7 +425,7 @@ private void onScheduleExactAlarmPermissionResult() {
warning = OSLCNOWarning.EXACT_PERMISSION;
}

schedule(notificationArguments, callbackContext);
schedule(notificationArguments, callbackContext, false);
}

/**
Expand Down

0 comments on commit 5122e8a

Please sign in to comment.