如何在状态栏中创建没有图标的通知或只是隐藏它?

Mer*_*yth 12 icons android android-notifications android-statusbar

我想知道如何创建一个不在状态栏中显示图标的通知.

有一种方法可以隐藏它吗?

Flo*_*ern 32

从Android 4.1(API级别16)开始,就可以指定通知了priority.如果您将该标志设置PRIORITY_MIN为通知图标将不会显示在状态栏上.

notification.priority = Notification.PRIORITY_MIN;
Run Code Online (Sandbox Code Playgroud)

或者如果你使用Notification.Builder:

builder.setPriority(Notification.PRIORITY_MIN);
Run Code Online (Sandbox Code Playgroud)

从Android 8.0 Oreo(API级别26)开始,您必须importance将通知设置NotificationChannelIMPORTANCE_MIN:

NotificationChannel channel = 
      new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
notificationManager.createNotificationChannel(channel);
...
builder.setChannelId(channel.getId())
Run Code Online (Sandbox Code Playgroud)


Aqi*_*mid -1

您可以通过使用完全透明的图像并将其用作图标来做到这一点。:)