0

I have a notification that is periodically updated after a certain period of time. The Foreground service is also associated with it, so it is constantly displayed. When updating data, I must recreate the notification with new ones, using the NotificationManager

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notification.setContentText("Updated Text");
    notificationManager.notify(NOTIFY_ID, notification.build());

When using this method, each time a notification arrives, it is displayed as new on the lock screen, and sound and vibration appear when it is received. But I would like to get rid of this.

Is it possible to do that the data is updated already in the existing notification, without the need to recreate it? For example, how this is done in a weather application, where the data is regularly updated directly in the current notification: Notification Widget

Edit

I apologize for my inaccuracy. As it turned out, I am changing the old notifacation, thanks to @0X0nosugar for hint. I use the same ID for notification updating, but every second I get sound and vibration, as well as a continuous message on the lock screen that I have a new notification. Although I do not receive new ones, I am changing the same old notification.

A notification from my application constantly comes to the lock screen. However, this is not observed in the weather application. And I got this

  • @0X0nosugar Thanks, partly yes. As it turned out, I use the same method that was given in the answer to that question, but every second I get sound and vibration, as well as a continuous message on the lock screen that I have a new notification. Although I am changing the old notifacation. – Shandor Hachimann Feb 05 '20 at 19:13

1 Answers1

0

Whenever you use any different notification ID like in your code, it will generate a new notification.

So, use a static nofiy_id (for example defined in your strings.xml) and call it.

Or just use it like this:

notificationManager.notify(0, notification.build());
Umut OVECOGLU
  • 154
  • 1
  • 6