【问题标题】:Stacked notifications not working on closed app堆叠的通知不适用于已关闭的应用程序
【发布时间】:2016-10-07 07:30:13
【问题描述】:

如果应用程序打开但不是在应用程序关闭时,我会收到堆叠通知。如果应用关闭,图标不正确,通知没有堆叠?

这是我的代码:

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);
    }
}

【问题讨论】:

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


    【解决方案1】:

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

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

    当应用程序在前台使用 DATA 负载和使用 NOTIFICATION 负载时管理通知,当应用程序在后台或被杀死时处理它们。

    因此,解决方案是从消息负载中删除通知对象。在后端删除通知对象将默认考虑数据负载对象,因为您不会再遇到这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2017-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多