繁体   English   中英

当接收方设备未在Android中使用FCM处于前台状态时,如何从设备发送推送通知?

[英]How to send Push Notification from device when the receiver device is not in foreground state using FCM in android?

我已经使用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
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM