【问题标题】:How to display the notification without playing any sound如何在不播放任何声音的情况下显示通知
【发布时间】:2019-08-24 12:42:18
【问题描述】:

我需要在不播放通知声音的情况下显示通知 使用通知生成器。

我尝试过使用

set sound(null);

我也尝试过使用自定义声音

这是我的代码:

public NotificationCompat.Builder getChannelNotification() {
   getData();
    return new NotificationCompat.Builder(getApplicationContext(), channelID)
            .setContentTitle(time)
            .setContentText(text)
            .setSmallIcon(R.drawable.ic_android)
            .setDefaults(0)
            .setPriority(NotificationCompat.PRIORITY_LOW)
            .setAutoCancel(true)
            .setOnlyAlertOnce(true)
            .setSound(null);

}

【问题讨论】:

  • 您尝试关闭哪个 android 版本
  • @AnasMehar,它是一个多版本的应用程序
  • @gaspar 你试试这个 setDefaults(Notification.DEFAULT_ALL) 代替 .setDefaults(0)
  • @Mohsinkazi,是的,它还在播放声音
  • @gaspar 您正在测试哪个版本

标签: java android


【解决方案1】:

删除builder.setDefaults(0); 的行。它不会播放声音,但如果愿意,您可能需要启用所有其他通知默认设置

【讨论】:

    猜你喜欢
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    相关资源
    最近更新 更多