如何在构建时发出不发出声音的通知?我正在构建一个通知,但我的用户不喜欢它发出声音这一事实。
我怎样才能把它改成静音/完全没有声音?
我如何显示通知:
android.support.v7.app.NotificationCompat.Builder builder = new android.support.v7.app.NotificationCompat.Builder(main);
builder.setStyle(new android.support.v7.app.NotificationCompat.BigTextStyle().bigText(text));
builder.setSmallIcon(R.drawable.app);
builder.setContentTitle("Rooster Maandag:");
builder.setOngoing(false);
builder.setAutoCancel(true);
builder.setSilent(true);
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
notificationManager = (NotificationManager) main.getSystemService(main.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());
我试图在谷歌上搜索,但我得到的唯一结果是如何播放声音,而不是如何不播放声音……
编辑 在某些人看来它可能是重复的,但在我看来我找不到指定默认值的替代方法,而这个新方法称为 setDefaults
原文由 Jason 发布,翻译遵循 CC BY-SA 4.0 许可协议
删除到
builder.setDefaults(Notification.DEFAULT_ALL);
的行。它不会播放声音,但如果愿意,您可能需要启用所有其他通知默认设置