Android通知声音无声

时间:2018-06-03 20:56:37

标签: android notifications

我制作了自定义notification,每次弹出它都会发送notification sound。我希望这是silent而不发出任何声音。我尝试使用下面的所有内容但似乎没有任何效果。似乎所有东西都被弃用,setPriority()不是一种选择。寻找有关如何让notification声音保持沉默的解决方案,有什么帮助吗?我的代码如下。

尝试使用以下所有内容的组合:

    status.sound = null;
    status.vibrate = null;
    status.defaults &= ~DEFAULT_SOUND;
    status.defaults &= ~DEFAULT_VIBRATE;
    status.vibrate = new long[] { -1 };
    status.priority = -2

我的代码

    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);

1 个答案:

答案 0 :(得分:0)

要在API 26中静音通知声音,请使用不包含任何声音的IMPORTANCE_LOW频道。例如:

 int importance = NotificationManager.IMPORTANCE_LOW;

此外,请务必清除应用数据或重新安装应用,以便在更改重要性后让此更改在通知渠道中生效。

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