0

I get the stacked notifications working if the app is opened but not when the app is closed. If the app is closed the icon is incorrect and the notifications are not stacked?

Here is my code:

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);
    }
}
Lion789
  • 4,402
  • 12
  • 58
  • 96

1 Answers1

0

For Firebase notifications,onMessageReceive is called when the app is in the foreground if you app if is background, the Google Services will take care of displaying your message.

Now notifications are handled using two ways: - notification payload - data payload

Notifications are managed when the app in the foreground using DATA Payload and using NOTIFICATION payload they are handled when the app in background or killed.

So, the solution for this is ditch the notification object from your message payload. Removing the notification object at backend will consider data payload object as default as you won't face this problem anymore.

TechInsect
  • 124
  • 1
  • 2