通知进度条在更新时发出声音 Android
Notificaiton progressbar produces sound on update Android
我一直在这样更新通知进度条。这被称为多次。但是通知声音会多次产生。这很烦人
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 模拟器上测试。
添加一个标记只提醒一次。
试试这个:
Notification notification = builder.build();
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notificationManager.notify(notificationId, notification);
我一直在这样更新通知进度条。这被称为多次。但是通知声音会多次产生。这很烦人
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 模拟器上测试。
添加一个标记只提醒一次。
试试这个:
Notification notification = builder.build();
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notificationManager.notify(notificationId, notification);