Kno*_*ing 7 service android android-notifications notification-channel
startForeground() 需要创建 NotificationChannel 以便它会在 Oreo 设备的启动器图标上显示徽章编号 1
如何以编程方式隐藏/禁用它?
因为 Galaxy S8(Oreo) 显示徽章编号 1。而 Android 8.0 模拟器也显示点。
这就是我现在所做的。但是 setShowBadge(false) 不起作用
编辑1:
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationChannel tmpC = new NotificationChannel(id, "basic", NotificationManager.IMPORTANCE_MIN);
tmpC.setShowBadge(false);
manager.createNotificationChannel(tmpC);
Notification notification = new NotificationCompat.Builder(this, id)
.setChannelId(id)
.setAutoCancel(true)
.build();
startForeground(getPackageName().hashCode(), notification);
Run Code Online (Sandbox Code Playgroud)
您所需要做的就是调用setShowBadge(false)您的NotificationChannel对象。
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Create notification channel.
NotificationChannel channel = new NotificationChannel({channel_id}, {name}, {importance});
mChannel.setShowBadge(false); // Disable badges for this notification channel.
mNotificationManager.createNotificationChannel(mChannel);
// Create notification and use channel
Notification notification = new NotificationCompat.Builder(context, {channel_id})
...
.build();
// notify
mNotificationManager.notify({notification_id}, notification)
Run Code Online (Sandbox Code Playgroud)
查看修改通知徽章。
| 归档时间: |
|
| 查看次数: |
3637 次 |
| 最近记录: |