-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[firebase_messaging] Notification blank on Android when backgrounded #3331
Comments
In case anyone asks, I added the the first answer here and also the tips in this issue because the one in the README does not work, specifically |
Thanks to this answer I was able to send a message that I could do something with even when the app was in the background or terminated:
I did not know that when sending a notification, you must also send a data component if you want to be able to process the message on Android with onResume or onLaunch, and I was feeling frustrated thinking the docs omitted that fact (or that it was a mistake). But then I found this: When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification. Source: https://firebase.google.com/docs/cloud-messaging/concept-options But that line is only partially true, because if I send the FCM message above to iOS when the Flutter app is terminated, both the notification portion and the data portion are present when tapping the notification opens the Flutter app, and even more surprising, both onResume and onLaunch are triggered (and both see the same message). Maybe this is just a difference between Android and iOS, but if you look at the handy table for various states (foreground/background/terminated on iOS and Android) in the FlutterFire docs then it implies a data message will not reach iOS at all when the app is terminated and that just the onLaunch fires for a notification when the iOS app is terminated. So maybe the plugin is doing something weird by firing both for iOS? I'm ok with that--I just need to watch for duplicates in that case. Anyway, if my use case is to show a notification message in the system tray and also display that message to the user, then I need to send the same message in both the notification and data portions. If my use case is to display a message in the system tray but I don't care about displaying that message in the app and just want to take some action based on hidden information when the app is open or opened, then that action information goes on the data portion. |
Hi @stephenhuey,
I think it'll be helpful if above is documented in the plugin. |
Send your Application calls pls. |
Pretty straightforward: in the Firebase cloud function I just call this:
where message is an object similar to the one I showed up above. But as @darshankawar mentioned, ideally the documentation would clarify that the
|
Sorry, typo. Send your Application.java class. |
Here it is. As you can see, I found a tip since the README is not correct.
|
Thanks man! Unfortunately it didn't solve to me |
Closing in favour of trying the latest messaging version which has been been heavily reworked, along with documentation, since this issue was raised: https://firebase.flutter.dev/docs/messaging/overviewIf you still have a problem please raise a new GitHub issue with up to date information and code snippets if possible. Thanks. |
I just upgraded my FlutterFire plugins to the versions that depend on the big breaking change of the new firebase_core and after following the migration guide, everything is working well for me (Firestore, Auth, etc). So for FCM my pubspec has
firebase_messaging: "^7.0.0"
. When I use the Cloud Messaging composer in the Firebase console and enter a Notification title and text there, I correctly receive it as attributes title and body on both iOS and Android. However, when my Android phone is backgrounded, I see the notification in the system tray but the information is missing, as you can see:As you may observe, I'm also putting the custom data key/value of click_action and FLUTTER_NOTIFICATION_CLICK in the Cloud Messaging composer form. My code which prints the output above looks like this:
This seems like a bug--shouldn't notification be populated? Again, I'm just using the Cloud Messaging composer in the Firebase console and it works in all other cases.
The text was updated successfully, but these errors were encountered: