This is my method for Notification
when I start Service
on android:
private void showNotification() {
Notification notification = new Notification(R.drawable.call, "Some text", System.currentTimeMillis());
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, getString(R.string.notification_label), getString(R.string.notification_text_short), pi);
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(7331, notification);
}
is it possible to change text later. Now is for example "Some text"
and later I would like to change it without stop and start service again.
Is that possible?
You are using the notification ID 7331 for showing a notification as well as starting the servie. As long as you are sending a new notification with the same ID, it will replace the old one.
Use this to update the notification
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(ns);
long when = System.currentTimeMillis();
Notification notification = new Notification("your icon", "your ticker text", when);
/*<set your intents here>*/
mNotificationManager.notify(7331, notification);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With