我设置了一个通知进度条,供用户上传文件时显示,但通知启动时,该通知条显示在屏幕顶部并振动并发出声音。我不想要那个,我只想要有关状态的通知,仅此而已。这是我的代码。
final double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
final int currentprogress = (int) progress;
String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
builder = new NotificationCompat.Builder(MultiPost.this, NOTIFICATION_CHANNEL_ID);
builder.setDefaults(Notification.DEFAULT_LIGHTS | DEFAULT_SOUND)
.setVibrate(new long[]{0L})// Passing null here silently fails
.setContentTitle("2 " +getResources().getString(R.string.on) +" " + String.valueOf(fileUriList.size()))
.setContentText("" + (int)progress +"%")
.setAutoCancel(false)
.setOngoing(true)
.setWhen(System.currentTimeMillis())
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setSmallIcon(R.mipmap.ic_launcher);
builder.setProgress(100,currentprogress,false);
mNotifyManager.notify(1001,builder.build());