for (int i = 0; i < 100; i++) {
try {
Thread.sleep(1000);//1秒后更新一下
builder.setDefaults(Notification.FLAG_ONLY_ALERT_ONCE);
//设置进度,max最大进度值,progress当前进度,indeterminate不确定的
builder.setProgress(100,i,false);
getManager().notify(2,builder.build());
} catch (InterruptedException e) {
e.printStackTrace();
}
}Notification.Builder builder = new Notification.Builder(this)
.setAutoCancel(true)
.setChannelId("test_channel_id")
.setContentTitle("新消息来了")
.setContentText("明天是周末,不用上班?你怕是在做梦!")
.setOnlyAlertOnce(true)
.setSmallIcon(R.mipmap.ic_launcher);
manager.notify(1, builder.build());
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 100; i++) {
try {
Thread.sleep(1000);
builder.setProgress(100, i, false);
manager.notify(1, builder.build());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
设置builder.setDefaults(Notification.FLAG_ONLY_ALERT_ONCE);这个是没有效果的