osimer pothe osimer pothe - 3 months ago 22
Android Question

How can I update existing notifications in Android ?

I am using the following code for displaying notification . Upon displaying the notification , I go to the activity if I click in the notifications .

void Notify(String notificationTitle, String notificationMessage){
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.noti, notificationTitle,System.currentTimeMillis());

Intent notificationIntent = new Intent(this, SmsActivity.class);

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent intent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

notification.setLatestEventInfo(this, notificationTitle,notificationMessage, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}


Now I want to update the text of notifications . How can I do that ?

Answer Source

You can update the text of notification by sending different text in Notify(String notificationTitle, String notificationMessage) method.