且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在android中未收到推送通知

更新时间:2022-04-22 22:01:19

用于将推送发送到特定设备.首先,您需要从 FCM 中选择令牌:

For sending the push to a specific device. First of all you need to pick the token from the FCM :

String token = FirebaseInstanceId.getInstance().getToken();

然后这个唯一的令牌用于从服务器发布请求发送推送请求.请找到帖子请求的标题以及所需的正文结构.

Then this unique token is used to send the push request from server post request. Please find the headers of the post request along with required structure of the body.

标题

Content-Type     'application/json'
Authorization    'key=(server-key)'

注意:标题中只允许使用这些值.这里的服务器密钥"是您从 FCM 控制台提供的浏览器密钥.

推送请求正文

{
  "data": {
    "NotificationDetailsID": 1131,
    "MessageGroup": "HR",
    "Message": "this is notification"
  },
  "to": "firebase-token-of-androidDevice"
}

这是服务器端实现,这肯定会起作用.正如我们最后测试的那样.即使应用程序关闭,您也会收到推送.