Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

android - How to create a notification without icon in the statusbar or simply hide it?

I'd like to know how to create a notification that doesn't show the icon in the statusbar.

There is a way to hide it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since Android 4.1 (API level 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.

notification.priority = Notification.PRIORITY_MIN;

Or in case you use a Notification.Builder:

builder.setPriority(Notification.PRIORITY_MIN);

As of Android 8.0 Oreo (API level 26) you have to set the importance of the notification's NotificationChannel to IMPORTANCE_MIN:

NotificationChannel channel = 
      new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
notificationManager.createNotificationChannel(channel);
...
builder.setChannelId(channel.getId())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...