首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android通知声音静默

Android通知声音静默
EN

Stack Overflow用户
提问于 2018-06-04 04:56:37
回答 1查看 3.5K关注 0票数 2

我有一个我构建的自定义notification,每次弹出它都会发送一个notification sound。我希望这是silent,不要发出任何声音。我已经尝试了下面的所有方法,但似乎都不起作用。所有的东西似乎都被弃用了,setPriority()不是一个选项。正在寻找如何让notification声音保持静音的解决方案,有什么帮助吗?我的代码如下。

尝试使用以下所有方法的组合:

代码语言:javascript
复制
    status.sound = null;
    status.vibrate = null;
    status.defaults &= ~DEFAULT_SOUND;
    status.defaults &= ~DEFAULT_VIBRATE;
    status.vibrate = new long[] { -1 };
    status.priority = -2

我的代码

代码语言:javascript
复制
    Notification status = new NotificationCompat.Builder(this, CHANNEL_1_ID).build();
    status.contentView = views;
    status.bigContentView = bigViews;
    status.flags = Notification.FLAG_ONGOING_EVENT;
    status.icon = R.drawable.ic_music_note;
    status.contentIntent = pendingIntent;
    status.priority = -2;
    startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, status);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-04 05:21:05

要使API26中的通知声音静音,请使用IMPORTANCE_LOW通道,该通道不包含任何声音。示例:

代码语言:javascript
复制
 int importance = NotificationManager.IMPORTANCE_LOW;

此外,请确保清除应用程序数据或重新安装应用程序,以便在更改重要性后,此更改在通知通道中生效。

参考文档:Migrating MediaStyle Notifications to Support Android O

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50670902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档