-
Notifications
You must be signed in to change notification settings - Fork 4k
[Firebase messaging]: Duplicate notifications on android #17330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @russellwheatley, in regards to when notifications randomly stop completely when app is in background, can you please let me know if this GPT answer is valid? It is suggesting that issue is not really the data-only payload, but the DART isolate being killed by the system when app is quit or in background. And it is suggesting to handle notifications with GPT:
This makes notifications less reliable, especially when:
In contrast, Native Android (Java/Kotlin) FCM integration:
Why This Is Better for Silent + Custom Alerts
But Isn’t It Still a Data Message?
TL;DR |
@iosephmagno - I think that chatGPT answer doesn't make sense. We aren't relying on Flutter SDK to receive notifications, and receiving messages isn't reliant on the main Dart isolate running otherwise we wouldn't receive messages. We are using native android API to listen for messages. See receiver: https://github.com/firebase/flutterfire/blob/main/packages/firebase_messaging/firebase_messaging/android/src/main/java/io/flutter/plugins/firebase/messaging/FlutterFirebaseMessagingReceiver.java We also need to fire up a background Flutter engine to communicate with your Flutter app otherwise you would never receive the messages in you Flutter background handler. You are more than welcome to fork off FlutterFire and use it in your own app, you could then post an update with your results if you have found a more reliable alternative. Native updates on android Firebase messaging are few and far between at this point so it wouldn't be that hard to keep it in sync with FlutterFire messaging. |
Hi there, you definitely had the right idea to disable battery optimisations as that tends to cut off background processes as phone vendors such as Xiaomi like to do this to claim more battery life https://dontkillmyapp.com/xiaomi. I have not been able to reproduce this issue using other android devices, in my case a Pixel and an S21. Unfortunately I don't think we can do anything about it. |
@russellwheatley - I discovered something that I think might be interesting for you to know. Writing this would take me 30m but I hope it is helpful. I was going to implement my native service to handle notifications directly on native, without relying on flutter firebase plugins (we do this already on IOS, as it is the only way to handle encrypted non-silent notifications on IOS with instant delivery). Anyway, while implementing this solution, I discovered something unexpected that allows our app to consistently display silent-notifications on android. I added a
As you can see I do nothing in I initialize firebase in MainActivity.kt
Here is the Manifest:
DISCOVERY
KEY POINTS:
My best guess is that being my NOTE: POTENTIAL IMPLICATIONS:
|
Yes, but those limitations aren't the root cause of the Flutter Firebase Messaging issue with notifications. On the same devices, native apps receive notifications and flutter apps don't. @russellwheatley this works only on Android. On IOS we had to move to native, as there's no way to make silent-notification quick and reliable on IOS. Maybe Firebase Messaging might do the same and provide the feature as part of the plugin:
|
Is there an existing issue for this?
Which plugins are affected?
Messaging
Which platforms are affected?
Android
Description
_firebaseMessagingForegroundHandler and _firebaseMessagingBackgroundHandler are fired multiple times for the same silent (data-only) notification - with firebase messaging 15.2.1
I'm reproducing the issue on android sdk34 Xiaomim Mi Lite 5g, though I saw past similar issues on IOS and this may still affect IOS as well.
Honestly, I’d rather deal with duplicate notifications than miss them entirely.
As a workaround, I’ve implemented a simple cache of notification IDs and filter out duplicates before displaying any alerts. Example code below:
I'm still experiencing issues with Android intermittently throttling or blocking push notifications, only to deliver them all at once later. Disabling battery optimizations and enabling autostart improves reliability somewhat, but overall, notification delivery on Android remains inconsistent.
It would be great if the Firebase team could collaborate with the Android team to address this — ideally establishing a more consistent behavior across devices and limiting the ability of manufacturers to interfere with notification delivery mechanisms.
Reproducing the issue
Send a notification to your device.
Firebase Core version
^3.1.1
Flutter Version
3.24.5
Relevant Log Output
Flutter dependencies
Expand
Flutter dependencies
snippetReplace this line with the contents of your `flutter pub deps -- --style=compact`.
Additional context and comments
No response
The text was updated successfully, but these errors were encountered: