Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android通知声音变为静音_Android_Notifications - Fatal编程技术网

Android通知声音变为静音

Android通知声音变为静音,android,notifications,Android,Notifications,我创建了一个自定义的通知,每次它弹出时都会发出通知声音。我希望这是无声的,不发出任何声音。我试着使用下面的所有东西,但似乎没有任何效果。似乎所有内容都已弃用,setPriority()不是选项。正在寻找如何使通知声音静音的解决方案,是否有帮助?我的代码如下 尝试使用以下所有选项的组合: 我的代码 Notification status = new NotificationCompat.Builder(this, CHANNEL_1_ID).build(); status.cont

我创建了一个自定义的
通知
,每次它弹出时都会发出
通知声音
。我希望这是
无声的
,不发出任何声音。我试着使用下面的所有东西,但似乎没有任何效果。似乎所有内容都已弃用,
setPriority()
不是选项。正在寻找如何使
通知
声音静音的解决方案,是否有帮助?我的代码如下

尝试使用以下所有选项的组合:

我的代码

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

要使API 26中的通知声音静音,请使用不包含任何声音的
重要性\u LOW
频道。例如:

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


参考文档:

我将在何处添加此内容?我能够修复它。我必须建立一个新的渠道,降低重要性。
 int importance = NotificationManager.IMPORTANCE_LOW;