当我使用NotificationManager.IMPORTANCE_LOW禁用声音时,通知不会出现在状态栏中。看到频道设置时,我有:中没有声音。
这是我所有的代码
Notification notification = notificationBuilder.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
NotifCmtManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(!checkGroupSon) {
/* Create or update. */
mChannel = new NotificationChannel("comment", "YuYu", NotificationManager.IMPORTANCE_HIGH);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
assert mChannel != null;
notificationBuilder.setChannelId("comment");
NotifCmtManager.deleteNotificationChannel("noS");
NotifCmtManager.createNotificationChannel(mChannel);
}else{
/* Create or update. */
mChannel = new NotificationChannel("noS", "YuYu No Sound", NotificationManager.IMPORTANCE_LOW);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
// mChannel.setSound(null,null);
mChannel.enableVibration(true);
assert mChannel != null;
notificationBuilder.setChannelId("noS");
NotifCmtManager.deleteNotificationChannel("comment");
NotifCmtManager.createNotificationChannel(mChannel);
}
}
NotifCmtManager.notify(ID_NOTIFICATIONCMT, notification);
答案 0 :(得分:1)
IMPORTANCE_LOW
通知仅在没有其他更重要的通知填充所有状态栏空间时才会显示在状态栏中。
要提高通知图标在状态栏中显示的机会,您可以使用IMPORTANCE_DEFAULT
频道。要禁用声音,您可以为频道设置null
声音:
mChannel = new NotificationChannel("comment_notSound", "YuYu No Sound",
NotificationManager.IMPORTANCE_DEFAULT);
mChannel.setSound(null, null);