Sumi
Sumi

Reputation: 157

New Firebase notification replacing existing unread Firebase Notification

I followed this link Firebase Notification and can able to send the notification to single device and multiple devices. But, newly arriving notification is replacing already existing unread notification in the tray. Please tell me a way to stop this and display all unread notifications in tray.

Note: Tutorial is regarding GCM. I did necessary changes for FCM.

Upvotes: 2

Views: 726

Answers (1)

Sumi
Sumi

Reputation: 157

Solved the issue by generating a random number as id and feeding it in notify() method

 public void showSmallNotification(String title, String message, Intent intent) {
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    mCtx,
                    ID_SMALL_NOTIFICATION,
                    intent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );


    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
    Notification notification;
    notification = mBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentIntent(resultPendingIntent)
            .setContentTitle(title)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
            .setContentText(message)
            .build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    Random random = new Random();
    int m = random.nextInt(9999 - 1000) + 1000;


    NotificationManager notificationManager = (NotificationManager)     mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(m, notification);
}

Upvotes: 1

Related Questions