Android O:IMPORTANCE_LOW通知,默认情况下展开

时间:2018-08-15 08:48:04

标签: android android-notifications android-8.0-oreo

在早期版本的Android中,可能会收到一条通知,该通知在状态栏中没有显示图标,但默认情况下使用priority设置进​​行了扩展。

// Hide status bar icon AND show notification as expanded
builder.setPriority(NotificationCompat.PRIORITY_MIN);

但是,现在在运行Android 26的设备上定位Android 25(Oreo)时,看来这是不可能的。当将重要性级别设置为IMPORTANCE_MIN时,可以达到不在状态栏中显示图标的预期效果。但是,默认情况下,通知是“折叠的”。

// Hide status bar icon (but notification is collapsed)
NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_MIN);

如果我将重要性级别设置为IMPORTANCE_LOW(或更高),则默认情况下会展开通知,但状态栏中会显示一个图标。

// Expand notification (but shows status bar icon)
NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_LOW);

使用IMPORTANCE_MIN时是否有任何方法可以强制在默认情况下扩展通知?也许我错过了一些设置。

PS:请不要建议使用setSmallIcon来透明。那只是一个看起来很糟糕的旧丑陋的黑客。


通过“折叠”和“展开”,我的意思是:

崩溃: collapsed

展开: expanded



源代码段

NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_LOW);
notifManager.createNotificationChannel(channel);

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID);
builder.setContent(myRemoteViews);
builder.setSmallIcon(R.drawable.status);
builder.setOngoing(true);
builder.setTicker(tickerText);
builder.setPriority(NotificationCompat.PRIORITY_MIN);

Notification notif = builder.build();
notifManager.notify(NOTIF_ID, notif);

0 个答案:

没有答案
相关问题