1

How can I make a persistent notification, that will update every time the users sees it? form the service

aclowkay
  • 3,577
  • 5
  • 35
  • 66

1 Answers1

6

To show the notification when the Service is running, you call:

    startForeground(R.string.notification_id, myNotification);

giving the method an ID for your service, and a Notification that you have created.


At any point, your Service can update what the user sees by using the same R.string.notification_id and posting a new Notification:

    NotificationManager notificationManager = 
        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(R.string.notification_id, myNotification);

For creating a Notification, you need to read up on Notification.Builder (android docs here).

There is also a good answer on a related question: How exactly to use Notification.Builder? Apologies for not reposting his answer, but it includes a lot of code and will sort you out.

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • Say, time...when a user opens the notification slide thingy, he sees the current time. Is it possible? – aclowkay Jan 14 '13 at 18:28