I have a Flutter application using the firebase-messaging plugin for push notifications.
I register firebase like normal on the client, and I send the fcmToken
to the server.
Notifications are created via a python server using aiofcm
(which uses firebase's XMPP api). They're created like this:
message = aiofcm.Message(
device_token = t2,
notification = {
"title":notification_title,
"body":notification_body,
"sound":"default",
"tag":link
},
data = {
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
priority=aiofcm.PRIORITY_HIGH
)
await fcm.send_message(message)
On iOS, notifications pop-up at the top of the screen.
On Android, only the icon shows up in the notification tray - not any of the notification content. This is tested on a Pixel 3 and a OnePlus 6, both running Android P.
Ideally, I would like the notification to be "heads-up" style like this:
Before I was able to accomplish this using data
messages and creating the notification programmatically in native android, however I would like to avoid that if possible since data messages don't get delivered on Android if the app is terminated.
Notifications Save this page to your Developer Profile to get notifications on important updates. Stay organized with collections Save and categorize content based on your preferences. Follow these steps to set up an FCM client on Flutter.
Firebase notifications behave differently depending on the foreground/background state of the receiving app. If you want foregrounded apps to receive notification messages or data messages, you'll need to write code to handle the onMessageReceived callback.
To Get heads-up - Notification - Kindly set "alert: true"
Example :
notification = {
"title":notification_title,
"body":notification_body,
"sound":"default",
"alert" : true
"tag":link
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With