From 9a841eae366e05888014f72ce9c29da7504be16a Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 8 Oct 2024 15:30:24 +0100 Subject: [PATCH] RMET-3699 Local Notifications - Fix notification not showing when app is on the foreground on Android (#34) * fix: deliver notification if 'foreground' option is 'true' Context: If the app is in the foreground, and the 'foreground' option is 'true', we want to deliver the notification References: https://outsystemsrd.atlassian.net/browse/RMET-3699 * chore: update changelog and set plugin to version `0.9.13 References: https://outsystemsrd.atlassian.net/browse/RMET-3699 * refactor: refactor code for better readability References: https://outsystemsrd.atlassian.net/browse/RMET-3699 --- CHANGELOG.md | 4 ++++ package.json | 2 +- plugin.xml | 2 +- src/android/notification/Notification.java | 7 +++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b340a20a2..139b16d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo #### Unreleased +#### 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) + #### Version 0.9.12 (27.09.2023) ### 12-09-2023 - Android: Make PendingIntents immutable for Android 14 [RMET-2666](https://outsystemsrd.atlassian.net/browse/RMET-2666) diff --git a/package.json b/package.json index be220a323..e5e3ee8fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-local-notification", - "version": "0.9.12", + "version": "0.9.13", "description": "Schedules and queries for local notifications", "cordova": { "id": "cordova-plugin-local-notification", diff --git a/plugin.xml b/plugin.xml index 899ea49c0..1e2bb8fb5 100644 --- a/plugin.xml +++ b/plugin.xml @@ -24,7 +24,7 @@ + version="0.9.13"> LocalNotification diff --git a/src/android/notification/Notification.java b/src/android/notification/Notification.java index 954e019af..06c9a1768 100644 --- a/src/android/notification/Notification.java +++ b/src/android/notification/Notification.java @@ -385,8 +385,11 @@ private void cancelScheduledAlarms() { * Present the local notification to user. */ public void show() { - // Don't show notification if the application is in foreground - if(applicationState == null || applicationState.equalsIgnoreCase("foreground")) return; + // Don't show notification if the application is in foreground and foreground option is false + boolean showEvenInForeground = getOptions().getDict().optBoolean("foreground", false); + + if (applicationState == null || (applicationState.equalsIgnoreCase("foreground") && !showEvenInForeground)) + return; if (builder == null) return;