关键点在于设置通知渠道的优先级:NotificationManager.IMPORTANCE_LOW
private void createNotifcaton() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_LOW); notificationManager.createNotificationChannel(channel); }
builder = new NotificationCompat.Builder(context,channelID)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(false)
.setChannelId(channelID)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
.setContentTitle("更新中...")
.setProgress(100,0, false)
.setContentText(("进度:0%"));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_PROGRESS);
}
}
private void updateNotifacation() {
builder.setProgress(100, (int) currentProgress, false)
.setContentText(("进度:" + (int) ((currentProgress) / ((double) 100) * 100) + "%"));
showNotifacation();
}
private void showNotifacation() {
notificationManager.notify(notificationId, builder.build());
}复制代码