【发布时间】:2017-02-10 02:31:28
【问题描述】:
如何在构建时发出不发出声音的通知?我正在构建一个通知,但我的用户不喜欢它发出声音的事实。
如何将其更改为静音/完全没有声音?
我如何显示通知:
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
【问题讨论】:
-
@PavneetSingh 抱歉,没有想到“禁用”这个词
-
让我大吃一惊,我不得不浪费时间研究如何获得无声通知。我试过这个(在 Xamarin 上)但没有运气:notificationBuilder.SetPriority(NotificationCompat.PriorityMin);
-
好像你不能改变一个频道的优先级,所以我不得不创建两个频道,一个低,另一个默认。
标签: java android notifications android-notifications ringtone