通知进度条在更新Android时发出声音

通知进度条在更新Android时发出声音,android,notifications,Android,Notifications,我一直在像这样更新通知进度条。这被称为多次。但通知声音会多次发出。这很烦人 builder.setProgress(100, percentage, false); notificationManager.notify(notifycation.notificationId, notifycation.builder.build()); 这是通知代码 public void initProgressNotificaiton(Context context) {

我一直在像这样更新通知进度条。这被称为多次。但通知声音会多次发出。这很烦人

     builder.setProgress(100, percentage, false); 
     notificationManager.notify(notifycation.notificationId, notifycation.builder.build());
这是通知代码

    public void initProgressNotificaiton(Context context) {

    notificationManager = NotificationManagerCompat.from(context);

    builder = new NotificationCompat.Builder(context, ChannelId);
    builder.setContentTitle("Video Upload")
            .setOngoing(true)
            .setContentText("Upload in progress")
            .setSound(null)
            .setSmallIcon(R.drawable.upload)
            .setPriority(NotificationCompat.PRIORITY_LOW);
    
    notificationManager.notify(notificationId, builder.build());
    
}
信道码

    public void createNotificationChannel(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = "naem";
        String description = "desc";
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(ChannelId, name, importance);
        channel.setSound(null, null);
        channel.setDescription(description);
        NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }

我该如何解决这个问题?在API 30 Emulator上测试。

添加一个标志以仅发出一次警报

试试这个:

Notification notification = builder.build();
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notificationManager.notify(notificationId, notification);