屏幕关闭FCM丢失通知

时间:2017-01-10 10:54:31

标签: android firebase push-notification firebase-cloud-messaging

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

通知托盘中也没有显示通知。这是FCM的一些错误,或者我做错了什么。

请查找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...%");    
            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

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

  success: function(data) {
       if (data.status == 'success') {
           alertify.success(data.msg);**// this line should dislay a message but instead of calling this , it directly calls employee_details(), data.msg is "Data saved Successfully"**; 
           data.user_type =3;
           if(data.hasOwnProperty('user_type')){
                if(data.user_type==2){
                    employeeDetails(data.id, tab_id);
                }else{
                    employee_details(data.id);
                }
            } else {
                return false;
            }

        }
    }

并且通知开始在android端工作。

答案 1 :(得分:0)

从firebase收到消息后,您是否在app中触发了通知

public void showNotification(String msg)
{
  Intent intent = new Intent(this, Home.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);

    // Build notification
    // Actions are just fake
    Notification noti = new Notification.Builder(this)
            .setContentTitle("title")
            .setContentText(msg).setSmallIcon(R.drawable.original_logo)
            .setContentIntent(pIntent)
            .addAction(R.drawable.original_logo, "Call", pIntent)
            .addAction(R.drawable.original_logo, "More", pIntent)
            .addAction(R.drawable.original_logo, "And more", pIntent).build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // hide the notification after its selected
    noti.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(0, noti);

}
相关问题