Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to hide NotificationCompat.Builder notification`s icon on status bar?

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.

like image 904
aphelion Avatar asked Apr 09 '13 12:04

aphelion


People also ask

How do I hide the notification icon on my status bar?

Tap Notifications > App Settings. In some versions of Android, you'll see your list of apps on the Notifications screen. Tap See All. Find the app with the notifications you want to turn off, and tap the toggle to turn off notifications.

How do I hide icon notifications on Android?

Once you're in the app settings, you'll notice the “Notifications” submenu. Open it. There you'll see a ton of notification options on a system level. You can basically choose to minimize status bar notifications for one particular type of notification.

How do I manage my status bar icons?

Scrolling down the Quick Menu from the top of the screen, tap the Settings icon > "Display" > "Status bar icon manager" and then you can enable or disable the icons on the status bar.


2 Answers

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());
like image 140
Floern Avatar answered Sep 20 '22 00:09

Floern


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.

like image 25
CommonsWare Avatar answered Sep 22 '22 00:09

CommonsWare