屏幕关闭FCM丢失通知

屏幕关闭FCM丢失通知

本文介绍了屏幕关闭FCM丢失通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在运行,我只是屏蔽了设备,FirebaseMessagingService内部没有任何通知事件.

My app is running I just screen off the device and no notification event is coming inside FirebaseMessagingService.

通知也未显示在通知托盘中.是FCM的错误还是我做错了?

The notification is also not showing in the notification tray. Is that some bug with FCM or I am doing something wrong.

请找到FCMService的附加代码.

public class FCMService extends FirebaseMessagingService {
    private static final Logger LOGGER = LoggerFactory.createLogger(FCMService.class);

    @Override
    public void onMessageReceived(RemoteMessage message) {
        if (null != message) {
            onNotificationReceived(message.getNotification(), message.getData());
        }
    }

    /**
     * Create and show a simple notification containing the received FCM message.
     * @param messageBody FCM message body received.
     * @param data Notification Data
     */
    private void onNotificationReceived(RemoteMessage.Notification messageBody, final Map<String, String> data) {
        LOGGER.info("Notification received... for data %s", data);
        if (AppPreferences.getInstance().isUserLogin()) {
            if (null != messageBody) {
               LOGGER.info("Notification received... Foreground Notification...%");
            } else {
               LOGGER.info("Notification received... Silent Notification...%");
            }
        }
    }
}

推荐答案

您的代码正确.您只需将priority设置为从服务器发送的邮件,并将其设置为high.在您的服务器端,将以下密钥添加到消息中:

Your code is correct. You just have to set the priority to your message sent from you server and set it to high. In you server end add following key to the message:

"priority" : "high",

通知将在android端开始工作.

And notification start working at android end.

这篇关于屏幕关闭FCM丢失通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:36