我有一个我构建的自定义notification
,每次弹出它都会发送一个notification sound
。我希望这是silent
,不要发出任何声音。我已经尝试了下面的所有方法,但似乎都不起作用。所有的东西似乎都被弃用了,setPriority()
不是一个选项。正在寻找如何让notification
声音保持静音的解决方案,有什么帮助吗?我的代码如下。
尝试使用以下所有方法的组合:
status.sound = null;
status.vibrate = null;
status.defaults &= ~DEFAULT_SOUND;
status.defaults &= ~DEFAULT_VIBRATE;
status.vibrate = new long[] { -1 };
status.priority = -2
我的代码
Notification status = new NotificationCompat.Builder(this, CHANNEL_1_ID).build();
status.contentView = views;
status.bigContentView = bigViews;
status.flags = Notification.FLAG_ONGOING_EVENT;
status.icon = R.drawable.ic_music_note;
status.contentIntent = pendingIntent;
status.priority = -2;
startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, status);
发布于 2018-06-04 05:21:05
要使API26中的通知声音静音,请使用IMPORTANCE_LOW
通道,该通道不包含任何声音。示例:
int importance = NotificationManager.IMPORTANCE_LOW;
此外,请确保清除应用程序数据或重新安装应用程序,以便在更改重要性后,此更改在通知通道中生效。
参考文档:Migrating MediaStyle Notifications to Support Android O
https://stackoverflow.com/questions/50670902
复制相似问题