В моем приложении используются уведомления Firebase. Если Firebase генерирует два уведомления с тем же id
, я показываю оба в своей строке состояния, но хочу, чтобы старое уведомление было удалено.Удаление устаревших уведомлений от Firebase
Мой код:
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(119);
notificationManager.notify(119 /* ID of notification */, notificationBuilder.build());
}
Вы хотите отправить так называемое сворачиваемое сообщение, что означает, что любое новое сообщение с тем же ключом заменяет предыдущее сообщение этим ключом. См. Https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages –
, если вы используете одинаковый идентификатор для каждого уведомления. чем предыдущее уведомление должно быть заменено новым. –
Как добавить параметр collapse_key, пожалуйста? –