6

I wrote application which uses FCM topic massaging to receive push notifications from server.

My HTTP request is:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to":"/topics/Foo-bar",
"priority":"high",
"content_available": true,
"data":{
    "notification-type":"chat",
    "target":"Current User",
    "title":"Current User has sent you a message",
    "text": "hello1",
    "badge": 5  //Badge you want to show on app icon
   }
}

And I got response as:

{
"message_id": 6199072048907273657
 }

But it doesn't receives Notification on device.

And how to print Notification data in debugger??

KENdi
  • 7,576
  • 2
  • 16
  • 31
tabassum
  • 1,100
  • 6
  • 17
  • 1
    The response indicates that the message sent successfully. Are you able to verify that the device is subscribed to the topic? – Jen Person Jan 03 '18 at 18:46
  • ya it was subscribed to topic – tabassum Jan 04 '18 at 04:02
  • Can you do some things for me? First, send a message to the specific device's token from the Firebase console. Include a data payload with the message. Send the message while the app is in the foreground. Is onMessageReceived performing the expected actions? Then send a message while the app is in the background. Do you receive a notification? This will rule out the client as the issue. Now the payload you're showing is for a data-only message. Are you intending to include a notification in the payload as well? If so, you need to include the `"notification"` key in the payload. – Jen Person Jan 04 '18 at 22:39
  • from firebase console to specific topic it was working when app is killed . Send the message while the app is in the foreground. Is onMessageReceived performing the expected actions? - in both case it was working i want to use data payload only using "data" payload it was working with foreground and background – tabassum Jan 05 '18 at 05:29

1 Answers1

1

Payload should be like this. Instead of data use notification object.

{
"to":"/topics/test",
"notification":{
    "type":"test",
    "title":"test!",
    "message":"test"
     }
}
Dmitry
  • 6,716
  • 14
  • 37
  • 39
sagarchavan
  • 187
  • 3
  • 14