Repository navigation
[Firebase_messaging] Double notification appear in release mode for some device (Flutter android) #18127
Replies: 1 comment
|
ran into this exact thing in my own app tbh. ngl the culprit is sending notification plus data together. when the app is backgrounded or killed, android takes the notification part and shows it on its own, you dont write any code for that one. so thats already one notification. if your code shows another one on top, you get the double. what fixed it for me: send data only, no notification block, and show the notification yourself with flutter_local_notifications in all three states, foreground, background, terminated. one path, one notification, no matter the device. since your background handler only logs and it only happens on that one oneplus in release, two things worth checking. log the message id in the background handler. same id twice means the system redelivered it, two different ids means your backend sent it twice. btw check your backend isnt holding onto old tokens. if it keeps every token without replacing on refresh, the device gets one copy per stored token. one more thing i noticed in your code, the handler that shows a local notification is defined but never registered, the print only one is whats actually wired up. if you ever swap them, youll get doubles everywhere, not just the oneplus. and the fact it only happens on the oneplus in release tracks, oxygenos kills and restarts background work aggressively, and release timing is different from debug, so thats where the redelivery shows up. |
Uh oh!
There was an error while loading. Please reload this page.
Hi every one, I'm trying to handle notification in my Flutter App, I'll start showing all the code and then telling you more about the problem I'm facing.
Inside my
main()function :FirebaseApi.dart (Handler class with all the functions called to handle notification):
Payload sent from my php backend:
The problem I'm facing:
-On iOS everything works (or at least for all the device I've been able to test)
-On android in debug mode works fine in any device, but on release mode I've noticed that sometimes a double notification is showed.
It happens just for a device I'm testing: One Plus 8t, Android 14. Oxygen OS KB2003_14.0.0.1311.
When the app is killed or in background a double notification is sent (just in this device, just in release mode, i've tested in debug mode and it works just like any other device), while in any other device I've tried it's not happening.
I've read the documentation talking about not sending both "notification" and "data" in the payload, but it has worked without any problem and if I don't send one of them I've other problems while handling the notification actions or the notification is not showed at all.
NOTICE THAT:
Inside
sendLocalNotificationthere's aif (Platform.isIOS) return;this because in the past I've noticed that iOS was already creating a notification in some cases by itself, and thus the local notification was not needed, if I hadn't add thisreturna double notification on iOS would have been sent, but on iOS every device had this behavior.I'm attaching some debug logs to show you what is happening in debug, unfortunately I'm not able to save the same logs on release mode to see what is happening.
Any help would really be appreciated.
All reactions