首页 > 解决方案 > Android FCM 通知第一次无法在后台工作

问题描述

Fcm Notification - onMessageReceived 在第一次安装应用程序时未在免费中调用。下次我打开和关闭应用程序时,它开始在后台工作。我在 Redmi k20 pro android 10 版本中进行测试。

有什么建议么

FCM 有效载荷:

{
   "to":"dmYZxw7MkC9y58NIK86dp1xypDkCQKBmikujvVtAFJC....",
   "priority":"high",
   "data":{
      "NotifyId":"12",
      "title":"777",
      "body":"1234456756778787878"
   },
   "notification":{
      "NotifyId":"12",
      "title":"777",
      "body":"1234456756778787878"
   }
}

收到消息时:

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        RemoteMessage.Notification notification = remoteMessage.getNotification();
        Map<String, String> data = remoteMessage.getData();
        Log.d("FROM", remoteMessage.getFrom());
        sendNotification(notification, data);
    }

标签: androidfirebase

解决方案


推荐阅读