How to send notifications using Android Firebase

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

要查看或添加评论,请登录

Anastasiya Liverant的更多文章

社区洞察

其他会员也浏览了