gpt4 book ai didi

java - 如何在没有声音的情况下显示通知java

转载 作者:太空狗 更新时间:2023-10-29 22:59:24 25 4
gpt4 key购买 nike

如何在构建时发出不发出声音的通知?我正在构建一个通知,但我的用户不喜欢它发出声音这一事实。

我怎样才能把它变成静音/完全没有声音?

我如何显示通知:

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

最佳答案

要在 OREO 8.1 中禁用声音,将通知的优先级更改为 LOW,它将禁用通知声音:

NotificationManager.IMPORTANCE_LOW

代码如下:

NotificationChannel chan1 = new NotificationChannel("default", "default", NotificationManager.IMPORTANCE_LOW);

关于java - 如何在没有声音的情况下显示通知java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39809702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com