onmyway133 / PushNotifications

🐉 A macOS, Linux, Windows app to test push notifications on iOS and Android
https://onmyway133.com
Other
2.26k stars 176 forks source link

Android mode only sends "data" portion of message, not "notification" {"title" and "body"} #38

Closed gjamesberigan closed 4 years ago

gjamesberigan commented 4 years ago

Firebase messages can have both a data object and a notification object JSON data, but PushNotifications only sends the data object. The notification object should contain title and body so that in Android getNotification() returns these fields and not null. Example from https://firebase.google.com/docs/cloud-messaging/concept-options below.

{ "message":{ "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification":{ "title":"Portugal vs. Denmark", "body":"great match!" }, "data" : { "Nick" : "Mario", "Room" : "PortugalVSDenmark" } } }

Ariandr commented 4 years ago

Hi @gjamesberigan I will check and see what we can do.

Ariandr commented 4 years ago

Hi @gjamesberigan We send the Android notifications directly to URL: https://fcm.googleapis.com/fcm/send

It requires the next format:

Headers:

Authorization: key="Your Firebase server key"
Content-Type: application/json

Body:

{
  "to": "device token",
  "data": {
    "title": "Notification title",
    "message": "Notification message",
    "key1" : "value1",
    "key2" : "value2"
   }
}

So, I just updated the default pre-filled message to include 'title' and 'message' fields, but overall it doesn't have to be different from the current implementation.

plamenterziev commented 3 years ago

Hi @Ariandr

I am also unable to get the notification when the app is in background. I am sending notification with title and body and it doesn't appear on the device. However if the app is in foreground and send again the notification then can see that the data is received. So it looks like that the payload is for data message and not for notification type.