Send FCM messages from server side to android device

前端 未结 7 1534
情话喂你
情话喂你 2020-12-03 05:45

With the new update, FCM is now going to be used.

I tried the sample app from git and it\'s working all fine. I can send notifications from the console.

But

7条回答
  •  一生所求
    2020-12-03 06:11

    In order to receive the notification using remoteMessage.getNotification().getBody(), you have to use the predefined set of key option for notification.

    In this case, "notification" is the key word.

    The JSON response has to be formatted like this.

       {
          "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
          "notification" : {
              "body" : "great match!",
              "title" : "Portugal vs. Denmark",
              "icon" : "myicon"
          }
       }
    

    You can also send notification and data payload in the same JSON response

     {
        "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
        "notification" : {
            "body" : "great match!",
            "title" : "Portugal vs. Denmark",
            "icon" : "myicon"
        },
        "data" : {
            "Nick" : "Mario",
            "Room" : "PortugalVSDenmark"
        }
     }
    

    see this: https://firebase.google.com/docs/cloud-messaging/concept-options#messages-with-both-notification-and-data-payloads

提交回复
热议问题