Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 762f4c0

Browse files
committed
Fix behaviour of popInitialNotification and onNotification.
Fix foreground value.
1 parent 271461e commit 762f4c0

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ private Bundle getBundleFromIntent(Intent intent) {
8989
public void onNewIntent(Intent intent) {
9090
Bundle bundle = this.getBundleFromIntent(intent);
9191
if (bundle != null) {
92-
bundle.putBoolean("foreground", false);
93-
intent.putExtra("notification", bundle);
9492
mJsDelivery.notifyNotification(bundle);
9593
}
9694
}

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
422422

423423
Intent intent = new Intent(context, intentClass);
424424
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
425+
bundle.putBoolean("foreground", this.isApplicationInForeground());
425426
bundle.putBoolean("userInteraction", true);
426427
intent.putExtra("notification", bundle);
427428

@@ -583,7 +584,7 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
583584
editor.apply();
584585
}
585586

586-
if (!(this.isApplicationInForeground(context) && bundle.getBoolean("ignoreInForeground"))) {
587+
if (!(this.isApplicationInForeground() && bundle.getBoolean("ignoreInForeground"))) {
587588
Notification info = notification.build();
588589
info.defaults |= Notification.DEFAULT_LIGHTS;
589590

@@ -938,7 +939,7 @@ private void checkOrCreateChannel(NotificationManager manager, String channel_id
938939
}
939940
}
940941

941-
public boolean isApplicationInForeground(Context context) {
942+
public boolean isApplicationInForeground() {
942943
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
943944
List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
944945
if (processInfos != null) {

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationPublisher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void handleLocalNotification(Context context, Bundle bundle) {
4040
Application applicationContext = (Application) context.getApplicationContext();
4141
RNPushNotificationHelper pushNotificationHelper = new RNPushNotificationHelper(applicationContext);
4242

43-
boolean isForeground = pushNotificationHelper.isApplicationInForeground(applicationContext);
43+
boolean isForeground = pushNotificationHelper.isApplicationInForeground();
4444

4545
Log.v(LOG_TAG, "sendNotification: " + bundle);
4646

index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var Notifications = {
2020
onAction: false,
2121
onRemoteFetch: false,
2222
isLoaded: false,
23-
idInitialNotification: null,
23+
isPopInitialNotification: false,
2424

2525
isPermissionsRequestPending: false,
2626

@@ -102,15 +102,16 @@ Notifications.configure = function(options) {
102102

103103
if (options.popInitialNotification === undefined || options.popInitialNotification === true) {
104104
this.popInitialNotification(function(firstNotification) {
105-
if (!firstNotification) {
105+
if(this.isPopInitialNotification) {
106106
return;
107107
}
108-
109-
if(false === firstNotification.userInteraction || this.idInitialNotification === firstNotification.id) {
108+
109+
this.isPopInitialNotification = true;
110+
111+
if (!firstNotification || false === firstNotification.userInteraction) {
110112
return;
111113
}
112114

113-
this.idInitialNotification = firstNotification.id;
114115
this._onNotification(firstNotification, true);
115116
}.bind(this));
116117
}

0 commit comments

Comments
 (0)