am尝试制作进度条通知,一切正常 但问题是我无法取消通知 每次我擦 又来了 当我在上一个完成进度之前再次启动它时,进度bas正在复制 那么在这种情况下我该怎么办?
通知代码
private void startNotification() {
String value= mEditTextInput.getText().toString();
final int input2=Integer.parseInt(value);
Intent activityIntent = new Intent(Notification.this, Notification.class);
final PendingIntent contentIntent = PendingIntent.getActivity(Notification.this,
0, activityIntent, 0);
final NotificationCompat.Builder notification = new NotificationCompat.Builder(Notification.this, CHANNEL_1_ID)
.setSmallIcon(R.drawable.noti)
.setContentTitle("title")
.setContentText("text")
.setPriority(NotificationCompat.PRIORITY_LOW)
.setAutoCancel(true)
.setOngoing(false)
.setContentIntent(contentIntent)
.setColor(Color.BLUE)
.setOnlyAlertOnce(true)
.setProgress(input2, 0, false);
notificationManager.notify(1, notification.build());
new Thread(new Runnable() {
@Override
public void run() {
SystemClock.sleep(0);
for (int progress = 0; progress <= input2; progress += 1) {
notification.setProgress(input2, progress, false);
notificationManager.notify(1, notification.build());
SystemClock.sleep(1000);
}
notification.setContentText("finish")
.setProgress(0, 0, false)
.setOngoing(false)
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setColor(Color.RED);
;
notificationManager.notify(1, notification.build());
}
}).start();
}