Skip to content

Commit

Permalink
Merge pull request #1017 from OneSignal/fix/notification_click_listen…
Browse files Browse the repository at this point in the history
…er_cold_start

Fix: Notification click listener fires on cold start
  • Loading branch information
jennantilla authored Sep 6, 2024
2 parents 1e2f9e7 + dd3f899 commit 64883d2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/android/com/onesignal/cordova/OneSignalPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,17 @@ private boolean preventDefault(JSONArray data) {
* N O T I F I C A T I O N C L I C K L I S T E N E R
*/

private boolean hasAddedNotificationClickListener = false;

public boolean addNotificationClickListener(CallbackContext callbackContext) {
jsNotificationClickedCallback = callbackContext;
return true;
if (this.hasAddedNotificationClickListener) {
return false;
}

OneSignal.getNotifications().addClickListener(this);
jsNotificationClickedCallback = callbackContext;
hasAddedNotificationClickListener = true;
return true;
}

@Override
Expand Down Expand Up @@ -361,7 +369,6 @@ public boolean init(CallbackContext callbackContext, JSONArray data) {
OneSignal.getInAppMessages().addLifecycleListener(this);
OneSignal.getInAppMessages().addClickListener(this);
OneSignal.getNotifications().addForegroundLifecycleListener(this);
OneSignal.getNotifications().addClickListener(this);

CallbackHelper.callbackSuccessBoolean(callbackContext, true);
return true;
Expand Down

0 comments on commit 64883d2

Please sign in to comment.