我使用FCM创建了一对一聊天。我一度陷入困境,我想在设备未处于前台状态时发送推送通知。我是新手,任何人都可以建议我如何进行。 三江源
答案 0 :(得分:0)
您可以在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
}