Constraints.Builder
public final class Constraints.Builder
A Builder for a Constraints object.
Summary
Public constructors |
|---|
Builder() |
Public methods |
|
|---|---|
final @NonNull Constraints.Builder |
@RequiresApi(value = 24)Sets whether the |
final @NonNull Constraints |
build()Generates the |
final @NonNull Constraints.Builder |
setRequiredNetworkRequest(Sets whether device should have a particular |
final @NonNull Constraints.Builder |
setRequiredNetworkType(@NonNull NetworkType networkType)Sets whether device should have a particular |
final @NonNull Constraints.Builder |
setRequiresBatteryNotLow(boolean requiresBatteryNotLow)Sets whether device battery should be at an acceptable level for the |
final @NonNull Constraints.Builder |
setRequiresCharging(boolean requiresCharging)Sets whether device should be charging for the |
final @NonNull Constraints.Builder |
setRequiresDeviceIdle(boolean requiresDeviceIdle)Sets whether device should be idle for the |
final @NonNull Constraints.Builder |
setRequiresStorageNotLow(boolean requiresStorageNotLow)Sets whether the device's available storage should be at an acceptable level for the |
final @NonNull Constraints.Builder |
@RequiresApi(value = 26)Sets the maximum delay that is allowed from the first time a |
final @NonNull Constraints.Builder |
@RequiresApi(value = 24)Sets the maximum delay that is allowed from the first time a |
final @NonNull Constraints.Builder |
@RequiresApi(value = 26)Sets the delay that is allowed from the time a |
final @NonNull Constraints.Builder |
@RequiresApi(value = 24)Sets the delay that is allowed from the time a |
Public methods
addContentUriTrigger
@RequiresApi(value = 24)
public final @NonNull Constraints.Builder addContentUriTrigger(@NonNull Uri uri, boolean triggerForDescendants)
Sets whether the WorkRequest should run when a local content: Uri is updated. This functionality is identical to the one found in JobScheduler and is described in JobInfo.Builder#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri).
| Parameters | |
|---|---|
@NonNull Uri uri |
The local |
boolean triggerForDescendants |
|
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
build
public final @NonNull Constraints build()
Generates the Constraints from this Builder.
| Returns | |
|---|---|
@NonNull Constraints |
The |
setRequiredNetworkRequest
public final @NonNull Constraints.Builder setRequiredNetworkRequest(
@NonNull NetworkRequest networkRequest,
@NonNull NetworkType networkType
)
Sets whether device should have a particular NetworkRequest for the WorkRequest to run on the API levels >= 28 (Android P). For the older API levels, networkType will be used instead on the older platforms.
NetworkRequest with NetworkSpecifier set aren't supported, as well as NetworkRequest with setIncludeOtherUidNetworks set. IllegalArgumentException will be thrown if such requests are passed.
| Parameters | |
|---|---|
@NonNull NetworkRequest networkRequest |
|
@NonNull NetworkType networkType |
The type of network required for t |
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setRequiredNetworkType
public final @NonNull Constraints.Builder setRequiredNetworkType(@NonNull NetworkType networkType)
Sets whether device should have a particular NetworkType for the WorkRequest to run. The default value is NetworkType.NOT_REQUIRED.
| Parameters | |
|---|---|
@NonNull NetworkType networkType |
The type of network required for the work to run |
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setRequiresBatteryNotLow
public final @NonNull Constraints.Builder setRequiresBatteryNotLow(boolean requiresBatteryNotLow)
Sets whether device battery should be at an acceptable level for the WorkRequest to run. The default value is false.
| Parameters | |
|---|---|
boolean requiresBatteryNotLow |
|
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setRequiresCharging
public final @NonNull Constraints.Builder setRequiresCharging(boolean requiresCharging)
Sets whether device should be charging for the WorkRequest to run. The default value is false.
| Parameters | |
|---|---|
boolean requiresCharging |
|
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setRequiresDeviceIdle
public final @NonNull Constraints.Builder setRequiresDeviceIdle(boolean requiresDeviceIdle)
Sets whether device should be idle for the WorkRequest to run. The default value is false.
| Parameters | |
|---|---|
boolean requiresDeviceIdle |
|
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setRequiresStorageNotLow
public final @NonNull Constraints.Builder setRequiresStorageNotLow(boolean requiresStorageNotLow)
Sets whether the device's available storage should be at an acceptable level for the WorkRequest to run. The default value is false.
| Parameters | |
|---|---|
boolean requiresStorageNotLow |
|
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setTriggerContentMaxDelay
@RequiresApi(value = 26)
public final @NonNull Constraints.Builder setTriggerContentMaxDelay(@NonNull Duration duration)
Sets the maximum delay that is allowed from the first time a content: Uri change is detected to the time when the WorkRequest is scheduled. This functionality is identical to the one found in JobScheduler and is described in JobInfo.Builder#setTriggerContentMaxDelay(long).
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setTriggerContentMaxDelay
@RequiresApi(value = 24)
public final @NonNull Constraints.Builder setTriggerContentMaxDelay(long duration, @NonNull TimeUnit timeUnit)
Sets the maximum delay that is allowed from the first time a content: Uri change is detected to the time when the WorkRequest is scheduled. This functionality is identical to the one found in JobScheduler and is described in JobInfo.Builder#setTriggerContentMaxDelay(long).
| Parameters | |
|---|---|
long duration |
The length of the delay in |
@NonNull TimeUnit timeUnit |
The units of time for |
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setTriggerContentUpdateDelay
@RequiresApi(value = 26)
public final @NonNull Constraints.Builder setTriggerContentUpdateDelay(@NonNull Duration duration)
Sets the delay that is allowed from the time a content: Uri change is detected to the time when the WorkRequest is scheduled. If there are more changes during this time, the delay will be reset to the start of the most recent change. This functionality is identical to the one found in JobScheduler and is described in JobInfo.Builder#setTriggerContentUpdateDelay(long).
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |
setTriggerContentUpdateDelay
@RequiresApi(value = 24)
public final @NonNull Constraints.Builder setTriggerContentUpdateDelay(long duration, @NonNull TimeUnit timeUnit)
Sets the delay that is allowed from the time a content: Uri change is detected to the time when the WorkRequest is scheduled. If there are more changes during this time, the delay will be reset to the start of the most recent change. This functionality is identical to the one found in JobScheduler and is described in JobInfo.Builder#setTriggerContentUpdateDelay(long).
| Parameters | |
|---|---|
long duration |
The length of the delay in |
@NonNull TimeUnit timeUnit |
The units of time for |
| Returns | |
|---|---|
@NonNull Constraints.Builder |
The current |