如何在没有声音的情况下显示通知 [英] How to show a notification without a sound java
问题描述
如何在构建通知时发出不发出声音的通知?我正在建立通知,而我的用户不喜欢它发出声音的事实.
How can I make a notification that doesn't make a sound when I build it? I am building a notification, and my users don't like the fact that it makes a sound.
如何将其更改为无声/无声?
我如何显示通知:
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.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());
我尝试在Google上进行搜索,但我得到的唯一结果是如何播放声音,而不是不播放声音...
I tried to search on google, but the only results I get is HOW to play a sound, not HOW to not play a sound...
修改 在某些人看来,它可能是重复的,但是在我的我中,找不到这种指定默认值的替代方法,而这种新方法称为setDefaults
Edit It possibly is a duplicate in some people's eyes, but in mine I could not find out an alternative for the there specified default, while this new method is called setDefaults
推荐答案
将行移至builder.setDefaults(Notification.DEFAULT_ALL);
.它不会播放声音,但是如果需要,您可能需要启用所有其他通知默认值
Remove the line to builder.setDefaults(Notification.DEFAULT_ALL);
. It will not play the sound, but you may need to enable all other notification defaults if preferred
这篇关于如何在没有声音的情况下显示通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!