我使用 FCM 创建了一个一对一的聊天。我卡在某一点上,我想在设备不在前台状态时发送推送通知。我是新手,任何人都可以建议我如何继续。 谢谢
您可以在MyFirebaseMessagingService类中尝试以下代码:
if (remoteMessage.getData() != null && remoteMessage.getData().size() > 0) {
Log.d("TAGRK", "Message data payload: " + remoteMessage.getData());
message = "" + remoteMessage.getData().get(Config.MESSAGE_KEY);//MESSAGE_KEY is your key for message in your json.(eg. "message")
title = "" + remoteMessage.getData().get(Config.TITLE_KEY);//TITLE_KEY is your key for title in your json..(eg. "title")
//send pushnoification method
} else if (remoteMessage.getNotification() != null) {
Log.d("TAGRK", "Message Notification Body: " + remoteMessage.getNotification().getBody());
message = "" + remoteMessage.getNotification().getBody();
title = "" + remoteMessage.getNotification().getTitle();
//send pushnoification method
}