我需要显示通知而不播放通知声音 使用通知生成器。
我尝试使用
set sound(null);
我也尝试过使用自定义声音
这是我的代码:
public NotificationCompat.Builder getChannelNotification() {
getData();
return new NotificationCompat.Builder(getApplicationContext(), channelID)
.setContentTitle(time)
.setContentText(text)
.setSmallIcon(R.drawable.ic_android)
.setDefaults(0)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setSound(null);
}
最佳答案
删除 builder.setDefaults(0);
行。它不会播放声音,但如果愿意,您可能需要启用所有其他通知默认值
关于java - 如何在不播放任何声音的情况下显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57638052/