Heloo, I am building an app where I am using push notifications via Firebase Console. I want to know what is a difference between simply push-notification and cloud message? Is it that messages from cloud messaging are data messages(have key and value) and notifications are just text without key and value?Am I right?
Firebase API has two types of messages, they call them:
onMessageReceived()
method if your app is in foreground.Sample:
{
"notification" : { "body" : "Hi"}
}
onMessageReceived()
method.Sample:
{
"data" : { "message" : "Hi", "whatever_key": "value"}
}
IMPORTANT : You can't send data payload messages from Firebase Console, Console only delivers notification message. However using API you can send both type of messages.
To send a data payload message you have to make a curl request:
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..."
}
You can get the server key (AIzaSyZ-1u...0GBYzPu7Udno5aA), from firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key