plugins icon indicating copy to clipboard operation
plugins copied to clipboard

[@nativescript/local-notifications] Android - Message received callback fires multiple times

Open tommag21 opened this issue 2 years ago • 2 comments

Android version: 11

nativescript CLI: 8.2.3 @nativescript/android: 8.2.2 @nativescript/local-notifications: 6.0.0

When I tap a local notification, the onReceived function is called and all data is present.

LocalNotifications.addOnMessageReceivedCallback((message) => {
    // message: { id: 6471, title: 'TITLE', body: `BODY`, payload: {...}, badge: 1, ...}
  });

However, if I open to the app switcher and return to my app, the function is called again but the data object is almost empty. Every time I switch back to the app the callback fires.

{ event: 'default', foreground: true }

I have not tested yet on iOS or different Android versions.

tommag21 avatar Oct 04 '22 09:10 tommag21

I'm having the same issue. How can we fix this?

SmailHammour avatar Feb 22 '23 16:02 SmailHammour

Seems to be coming from here, it is the default event. You can just ignore the call if the message.event is 'default' https://github.com/NativeScript/plugins/blob/184555c1af63a079693d3e12ec2cd9baf285a803/packages/local-notifications/native-src/android/app/src/main/java/com/telerik/localnotifications/LifecycleCallbacks.java#L98

Another place a default event could originate from https://github.com/NativeScript/plugins/blob/184555c1af63a079693d3e12ec2cd9baf285a803/packages/local-notifications/native-src/android/app/src/main/java/com/telerik/localnotifications/NotificationActionReceiver.java#L80

shiv19 avatar Feb 22 '23 21:02 shiv19