3

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"
        }
    }
}
3squad
  • 355
  • 3
  • 14

1 Answers1

4

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

Hardik Mehta
  • 2,195
  • 1
  • 11
  • 14
  • 1
    but if we send notification object along with data object then it will show 2 notifications. One for notification by FCM sdk and one by the code we have written to handle data notification. – TechHelper Apr 09 '22 at 08:30
  • If you are getting notification object in notification then you have to comment out your code for handle this as its automatically handled by system so. – Hardik Mehta Apr 10 '22 at 04:02
  • But what if I want to handle that custom data myself and not automatically by FCM SDK? – TechHelper Apr 10 '22 at 11:22
  • then you have to send only data object not notification object in push then you can handle by self – Hardik Mehta Apr 11 '22 at 04:10
  • I want both the things 1. Notification should work always even after app is killed 2. I can not send both notification and data object. I can only send data object. – TechHelper Apr 11 '22 at 10:29
  • I think using priority is the way to go as mentioned here: https://stackoverflow.com/questions/48451761/firebase-message-with-high-priority-not-waking-device-from-doze-android-6 – TechHelper Apr 11 '22 at 10:31
  • currently we are using third party service which have only data payload so we have to handle that in our application now this thing works in foreground and background but not in kill mode. but in Android Native notification will pop up in all three scenario. if it is work in native then what is the issue with flutter ? – vmvyas1989 Feb 10 '23 at 12:43
  • @VasudevM.Vyas : try to run in release mode : https://stackoverflow.com/questions/73117054/flutter-fcm-message-not-coming-when-app-is-closed – Hardik Mehta Feb 16 '23 at 09:40