2

First, do this (tested on Nexus 5 running 4.4.2):

  • Pass a PRIORITY_LOW notification to Service.startForeground().
  • Observe notification is not shown in status bar.
  • Raise a PRIORITY_MAX notification using same notification ID.
  • Observe notification is shown in status bar.

Now, is there any way to remove that icon from the status bar (other than Service.stopForeground())?

I've tried calling NotificationManager.cancel() and NotificationManager.cancelAll(). And also tried raising the same original PRIORITY_LOW notification. But all of them leave the notification icon in the status bar.

Mark
  • 7,446
  • 5
  • 55
  • 75

2 Answers2

2

This was changed in Android 4.3, to always show notifications for foreground services.

There is a good reason for this, namely that foreground services cannot be killed when the system needs more resources. If the notification is not there, there is no way for a normal user to know that there is something still running and draining battery.

If you don't want the notification, consider using a background service instead. If you really need a foreground service, the user have the right to know.

Read more on http://commonsware.com/blog/2013/07/30/notifications-foreground-services-android-4p3.html

Tomas Skäre
  • 174
  • 5
  • As I understand it, the 4.3 change was to enforce persistent display of notifications, not status bar icons. Regardless, Android 4.4.2 does not show the status icon for PRIORITY_LOW notifications. This particular behaviour is WAI. – Mark Feb 03 '14 at 11:59
  • 1
    Oh, I see. I think I misunderstood your problem. It sounds more like a bug in Android, if it's possible to raise the priority but not lower it. – Tomas Skäre Feb 03 '14 at 13:33
0

One workaround is to call Service.stopForeground() followed by Service.startForeground().

Mark
  • 7,446
  • 5
  • 55
  • 75