前台服务 - 设置不确定的进度条
Foreground service - Setting an indeterminate progress bar
我正在使用 indeterminate progress bar
.
创建一个前台服务
public Notification createNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_TEST)
.setSmallIcon(R.drawable.ic_download_complete)
.setContentTitle("Test title")
.setContentText("Test content")
.setProgress(someInt, someInt, true) //What do I set for these two params before the boolean flag
.setPriority(NotificationCompat.PRIORITY_LOW)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = this.getSystemService(NotificationManager.class);
NotificationChannel channel = new NotificationChannel(
CHANNEL_TEST,
"Test notification",
NotificationManager.IMPORTANCE_LOW
);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
return builder.build();
}
我想了解我必须为 .setProgress
中的两个 int 参数设置什么值。该方法中的最后一个布尔标志用于将其设置为确定或不确定 progressbar
。因此,如果它是确定的,我们可以将两个整数更新为我们想要的百分比 .setProgress(100, 10, true)
,但是对于不确定的,我应该将值设置为什么?
我尝试检查该方法,但它并没有完全说明不确定使用什么。由于传递 null 不是一个选项
To display an indeterminate progress bar (a bar that does not indicate
percentage complete), call setProgress(0, 0, true). The result is an
indicator that has the same style as the progress bar above, except
the progress bar is a continuous animation that does not indicate
completion.
因此,您需要将两个 int
值设置为 0
我正在使用 indeterminate progress bar
.
public Notification createNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_TEST)
.setSmallIcon(R.drawable.ic_download_complete)
.setContentTitle("Test title")
.setContentText("Test content")
.setProgress(someInt, someInt, true) //What do I set for these two params before the boolean flag
.setPriority(NotificationCompat.PRIORITY_LOW)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = this.getSystemService(NotificationManager.class);
NotificationChannel channel = new NotificationChannel(
CHANNEL_TEST,
"Test notification",
NotificationManager.IMPORTANCE_LOW
);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
return builder.build();
}
我想了解我必须为 .setProgress
中的两个 int 参数设置什么值。该方法中的最后一个布尔标志用于将其设置为确定或不确定 progressbar
。因此,如果它是确定的,我们可以将两个整数更新为我们想要的百分比 .setProgress(100, 10, true)
,但是对于不确定的,我应该将值设置为什么?
我尝试检查该方法,但它并没有完全说明不确定使用什么。由于传递 null 不是一个选项
To display an indeterminate progress bar (a bar that does not indicate percentage complete), call setProgress(0, 0, true). The result is an indicator that has the same style as the progress bar above, except the progress bar is a continuous animation that does not indicate completion.
因此,您需要将两个 int
值设置为 0