5

My question is quite simple, but I couldn't get around it for a long time so I'm asking here.

How to hide the ongoing notification's icon, that is displayed in the status bar? I am creating the notification with NotificationCompat.Builder object. I tried to skip (when the option to show icon is unchecked) the builder.setSmallIcon() function call, but that resulted in no notification on the notifications screen.

Floern
  • 33,559
  • 24
  • 104
  • 119
aphelion
  • 561
  • 1
  • 5
  • 12

2 Answers2

15

Since Android 4.1 (API 16) it's possible to specify a notification's priority. If you set that flag to PRIORITY_MIN the notification icon won't show up on the statusbar.

builder.setPriority(NotificationCompat.PRIORITY_MIN);

As of Android 8.0 Oreo (API level 26) you have to create a NotificationChannel and set its importance to IMPORTANCE_MIN:

NotificationChannel channel = 
      new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
notificationManager.createNotificationChannel(channel);
...
builder.setChannelId(channel.getId());
Floern
  • 33,559
  • 24
  • 104
  • 119
  • That is a useful solution, but it will not work for me, because i tend to target earlier android versions. – aphelion Jun 16 '13 at 06:05
  • Just a note in Android 10, this solution still works **but** the notification gets collapsed in the notification shade, so the user needs to expand it in order to see it. – Sam Jan 20 '20 at 08:19
2

How to hide the ongoing notifications icon, that is displayed in status bar?

You don't.

I tried to skip (when the option to show icon is unchecked) the builder.setSmallIcon() function call, but that resulted in no notification in notifications screen.

Correct. Since the primary point of raising a Notification is to put an icon in the status bar, there is no means to not put an icon in the status bar.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Ok, thanks for clarifying that. :) So, if i understand correctly, when other apps offer an option to show/hide icon in runtime events, they operate with whole notification instead? P.s. I would raise the rate of your answer, but i dont have the min reputation level. – aphelion Apr 09 '13 at 13:13
  • @aphelion: "So, if i understand correctly, when other apps offer an option to show/hide icon in runtime events, they operate with whole notification instead?" -- presumably. – CommonsWare Apr 09 '13 at 14:23