How to send notifications using Android Firebase
This post covers how to send push notification using Android Firebase.
If you want to add on_click_action or any payload to notification (not only title/body) following link will be useful: https://firebase.google.com/docs/cloud-messaging/http-server-ref#data
N?ote: firebase console will not give you to add any payload - so for test use postman or any other app to make POST request https://fcm.googleapis.com/fcm/send.
Example with notification title , body and payload:
Headers:
Content-Type:application/json
Authorization:key=CloudMessagingKeyFromFirebaseConsole
Body:
{
"to" : "UserTokenThatArrived OnTokenRefresh()",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark"
},
"data": {
"key": "value"
}
}
Note2:
If app is open payload will arrive to FirebaseMessagingService -> onMessageReceived.
If app is closed payload will arrive as extra to launch activity.
Note 3:
Another more updated article