Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter/Firebase - How to get "heads up" notification on Android?

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:

enter image description here

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.

like image 821
bbedward Avatar asked Mar 11 '19 13:03

bbedward


People also ask

How do I get notifications from Firebase Flutter?

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.

How do I handle the firebase notification when an app is in foreground?

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.


1 Answers

To Get heads-up - Notification - Kindly set "alert: true"

Example :

notification = {
    "title":notification_title,
    "body":notification_body,
    "sound":"default",
    "alert" : true
    "tag":link
},
like image 55
ramkumar Avatar answered Sep 28 '22 04:09

ramkumar