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

前端 未结 5 1488
闹比i
闹比i 2021-01-02 00:42

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?

5条回答
  •  别那么骄傲
    2021-01-02 01:26

    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())
    

提交回复
热议问题