Skip to content

Commit

Permalink
RMET-3699 Local Notifications - Fix notification not showing when app…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
alexgerardojacinto authored Oct 8, 2024
1 parent bcd8c39 commit 9a841ea
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-local-notification"
version="0.9.12">
version="0.9.13">

<name>LocalNotification</name>

Expand Down
7 changes: 5 additions & 2 deletions src/android/notification/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9a841ea

Please sign in to comment.