android - Android 通知声音静音
问题描述
我有一个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);
解决方案
要在 API 26 中静音通知声音,请使用IMPORTANCE_LOW
不包含任何声音的通道。例子:
int importance = NotificationManager.IMPORTANCE_LOW;
另外,请务必清除应用数据或重新安装应用,以便在更改重要性后使此更改在通知渠道中生效。
推荐阅读
- r - dplyr 计数唯一并按月重复 id
- python - 在文件中排序日期(Python)
- javascript - 为什么我的 Go 服务器无法读取 Swift 帖子?
- swift - Swift - 表格视图 - 为多个数据重复不同部分的顺序
- sql - 在 SQL 中创建函数
- python - 如何在 Python 中检查属性是否为 True
- c# - 写入数据库并同时返回
- python - 有没有办法使用 iterparse lxml 跳过节点/元素?
- python - 尽管使用 ssh-keyscan 生成 known_hosts 文件,pysftp.CnOpts() 'No Host Keys Found' 错误
- react-native - 使用 React Native 更改 SVG 组件