堆叠通知不适用于已关闭的应用

时间:2016-10-07 07:30:14

标签: android firebase push-notification android-notifications firebase-notifications

如果应用程序已打开,我会收到堆叠通知,但应用程序关闭时却没有。如果该应用关闭,则图标不正确且通知未堆叠?

这是我的代码:

notification = new NotificationCompat.Builder(this);
notification.setContentTitle(notifyFromName);
notification.setContentText(notifyMsg);
if (!msgIsProj) {
    String followText = notifyMsg + " you!";
    notification.setContentText(followText);
    notification.setGroup(GROUP_KEY_FOLLOWERS);

    Log.d(Constants.DEBUG, "SETTING AS FOLLOWers" + unread_notif);
} else {

    notification.setContentText(notifyMsg + " " + notifyItemName);
    notification.setGroup(GROUP_KEY_PROJECTS);
}
notification.setTicker(getString(R.string.titlePushNotify));
notification.setSmallIcon(R.drawable.ic_pushnotify);
//notification.setGroupSummary(true);
PendingIntent contentIntent = PendingIntent.getActivity(this, id,
        newIntentMsg, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setContentIntent(contentIntent);
notification.setAutoCancel(true);
manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if(notifyMsg != null && !notifyMsg.equals("")) {

    manager.notify(id, notification.build());

    unread_notif++;

    Log.d(Constants.DEBUG, "PRE MORE NOTIF" + unread_notif);
    if (unread_notif>1) {
        Log.d(Constants.DEBUG, "GETTING MORE NOTIF" + unread_notif);
        Notification summaryNotification = new NotificationCompat.Builder(this)
                .setContentTitle("Your summary message")
                .setSmallIcon(R.drawable.ic_pushnotify)
                .setStyle(new NotificationCompat.InboxStyle()
                        .addLine("Details about your first notification")
                        .addLine("Details about your second notification")
                        .setBigContentTitle(Integer.toString(unread_notif)+" new notifications")
                        .setSummaryText("More details in app"))
                .setGroup(GROUP_KEY_FOLLOWERS)
                .setGroupSummary(true)
                .build();

        manager.notify(id++, summaryNotification);
    }
}

1 个答案:

答案 0 :(得分:0)

对于Firebase通知,当应用程序位于前台时调用onMessageReceive,如果您是应用程序,如果是后台,则Google服务将负责显示您的消息。

现在通过两种方式处理通知: - 通知有效载荷 - 数据有效载荷

当应用程序在前台使用DATA Payload并使用NOTIFICATION有效负载时,会在应用程序处于后台或被杀死时处理通知。

因此,解决方法是从消息有效负载中删除通知对象。删除后端的通知对象会将数据有效负载对象视为默认值,因为您将不再遇到此问题。