Unable to send data message using firebase console

30,853

Solution 1

You can now send notification message via the console. Note that it is different from data messages; notification messages only trigger the onMessageReceived callback when the app is in the foreground.

They are inside the advanced options tab on the compose message screen.

enter image description here

Just expand it and type your key/value map.

enter image description here

These will be included into the data field of the notification.

Solution 2

The Firebase Notifications Console can only be used to send notification messages. It cannot be used to send data messages.

See the table in message types in the Firebase documentation:

Notification message

Use scenario: FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys.

How to send:

  1. Use your app server and FCM server API: Set the notification key. May have optional data payload. Always collapsible.

  2. Use the Notifications console: Enter the Message Text, Title, etc., and send. Add optional data payload by providing Custom data in the Notifications console. Always collapsible.

Data message

Use scenario: Client app is responsible for processing data messages. Data messages have only custom key-value pairs.

How to send:

  • Use your app server and FCM server API: Set the data key only. Can be either collapsible or non-collapsible.

Solution 3

You can test both notification message and data message using Postman(rest client for testing http request).See screen shots:

enter image description here

In header pass:

key:Content-Type, value:application/json
key:Authorization:key=<Server key>

Solution 4

Please look here: Firebase push notifications update DB, my post from June.

In conclusion, you need send HTTP POST request to https://fcm.googleapis.com/fcm/send

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
"score": "5x1",
"time": "15:10"
},
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
Share:
30,853
amodkanthe
Author by

amodkanthe

Mobile app dev

Updated on January 20, 2020

Comments

  • amodkanthe
    amodkanthe over 4 years

    I'm using firebase console and can send only Notification messages using it.

    Is there a way to send data messages using the same?