当我构建它的时候,我怎么能发出没有声音的通知呢?我正在构建一个通知,我的用户不喜欢它发出声音的事实。
如何将其更改为静音/根本没有声音?
如何显示通知:
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
发布于 2016-10-02 01:57:14
删除到builder.setDefaults(Notification.DEFAULT_ALL);的行。它不会播放声音,但如果愿意,您可能需要启用所有其他通知默认值
发布于 2018-07-25 21:34:18
要禁用OREO 8.1中的声音,请将通知的优先级更改为低,它将禁用通知的声音:
NotificationManager.IMPORTANCE_LOW代码如下:
NotificationChannel chan1 = new NotificationChannel("default", "default", NotificationManager.IMPORTANCE_LOW);发布于 2018-08-02 15:06:46
它在Android Oreo上适用于我。
你应该像这样写你的频道:
NotificationChannel notificationChannel = new NotificationChannel("Id" , "Name", NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.setSound(null, null);
notificationChannel.setShowBadge(false);
notificationManager.createNotificationChannel(notificationChannel);https://stackoverflow.com/questions/39809702
复制相似问题