Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter / Firebase push notifications not fired when app is closed

I am using firebase messaging to send notifications to users in flutter application, and everything is working fine when I am sending notification from postman (notification always shows), but then when I want to send the same notification from my backend server, notification not showing on device. On server logs I can see that notification was send with success like this:

{
    "multicast_id": XXXXXXXXXXXXX,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "XXXXXXXXXXXXX"
        }
    ]
}

So it means it was correctly send to messaging services, but push notification not firing on device.

Sometimes when I open app (going to foreground of application) then notification somehow shows, but I need users to see notification always, especially when their app is closed.

I am sending notification with high priority so this is not an issue.

Any help, what could be potential issue with this?

My request to FCM:

POST: https://fcm.googleapis.com/fcm/send Authorization: key=xxxx_MY_KEY_XXXXX Content-Type: application/json

{
    "to": "xxxxxMY_FCM_TOKEN_xxxxxx",
    "mutable_content": true,
    "content_available": true,
    "priority": "high",
    "data": {
        "content": {
            "id": 106,
            "channelKey": "remote_chann",
            "title": "Hello",
            "body": "test",
            "notificationLayout": "Messaging"
        }
    }
}
like image 870
3squad Avatar asked Nov 16 '25 09:11

3squad


1 Answers

As per your data send with fcm is sending only data object not notification object as per the fcm to wakeup it self you need to send notification object along with data object.

https://firebase.google.com/docs/cloud-messaging/concept-options enter image description here

like image 194
Hardik Mehta Avatar answered Nov 18 '25 23:11

Hardik Mehta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!