Constraints.Builder
class Constraints.Builder
A Builder for a Constraints object.
Summary
Public constructors |
|---|
Builder() |
Public functions |
|
|---|---|
Constraints.Builder |
@RequiresApi(value = 24)Sets whether the |
Constraints |
build()Generates the |
Constraints.Builder |
setRequiredNetworkRequest(Sets whether device should have a particular |
Constraints.Builder |
setRequiredNetworkType(networkType: NetworkType)Sets whether device should have a particular |
Constraints.Builder |
setRequiresBatteryNotLow(requiresBatteryNotLow: Boolean)Sets whether device battery should be at an acceptable level for the |
Constraints.Builder |
setRequiresCharging(requiresCharging: Boolean)Sets whether device should be charging for the |
Constraints.Builder |
setRequiresDeviceIdle(requiresDeviceIdle: Boolean)Sets whether device should be idle for the |
Constraints.Builder |
setRequiresStorageNotLow(requiresStorageNotLow: Boolean)Sets whether the device's available storage should be at an acceptable level for the |
Constraints.Builder |
@RequiresApi(value = 26)Sets the maximum delay that is allowed from the first time a |
Constraints.Builder |
@RequiresApi(value = 24)Sets the maximum delay that is allowed from the first time a |
Constraints.Builder |
@RequiresApi(value = 26)Sets the delay that is allowed from the time a |
Constraints.Builder |
@RequiresApi(value = 24)Sets the delay that is allowed from the time a |
Public functions
addContentUriTrigger
@RequiresApi(value = 24)
fun addContentUriTrigger(uri: Uri, triggerForDescendants: Boolean): Constraints.Builder
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 | |
|---|---|
uri: Uri |
The local |
triggerForDescendants: Boolean |
|
| Returns | |
|---|---|
Constraints.Builder |
The current |
build
fun build(): Constraints
Generates the Constraints from this Builder.
| Returns | |
|---|---|
Constraints |
The |
setRequiredNetworkRequest
fun setRequiredNetworkRequest(
networkRequest: NetworkRequest,
networkType: NetworkType
): Constraints.Builder
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 | |
|---|---|
networkRequest: NetworkRequest |
|
networkType: NetworkType |
The type of network required for t |
| Returns | |
|---|---|
Constraints.Builder |
The current |
setRequiredNetworkType
fun setRequiredNetworkType(networkType: NetworkType): Constraints.Builder
Sets whether device should have a particular NetworkType for the WorkRequest to run. The default value is NetworkType.NOT_REQUIRED.
| Parameters | |
|---|---|
networkType: NetworkType |
The type of network required for the work to run |
| Returns | |
|---|---|
Constraints.Builder |
The current |
setRequiresBatteryNotLow
fun setRequiresBatteryNotLow(requiresBatteryNotLow: Boolean): Constraints.Builder
Sets whether device battery should be at an acceptable level for the WorkRequest to run. The default value is false.
| Parameters | |
|---|---|
requiresBatteryNotLow: Boolean |
|
| Returns | |
|---|---|
Constraints.Builder |
The current |
setRequiresCharging
fun setRequiresCharging(requiresCharging: Boolean): Constraints.Builder
Sets whether device should be charging for the WorkRequest to run. The default value is false.
| Parameters | |
|---|---|
requiresCharging: Boolean |
|
| Returns | |
|---|---|
Constraints.Builder |
The current |
setRequiresDeviceIdle
fun setRequiresDeviceIdle(requiresDeviceIdle: Boolean): Constraints.Builder
Sets whether device should be idle for the WorkRequest to run. The default value is false.
| Parameters | |
|---|---|
requiresDeviceIdle: Boolean |
|
| Returns | |
|---|---|
Constraints.Builder |
The current |
setRequiresStorageNotLow
fun setRequiresStorageNotLow(requiresStorageNotLow: Boolean): Constraints.Builder
Sets whether the device's available storage should be at an acceptable level for the WorkRequest to run. The default value is false.
| Parameters | |
|---|---|
requiresStorageNotLow: Boolean |
|
| Returns | |
|---|---|
Constraints.Builder |
The current |
setTriggerContentMaxDelay
@RequiresApi(value = 26)
fun setTriggerContentMaxDelay(duration: Duration): Constraints.Builder
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 | |
|---|---|
duration: Duration |
The length of the delay |
| Returns | |
|---|---|
Constraints.Builder |
The current |
setTriggerContentMaxDelay
@RequiresApi(value = 24)
fun setTriggerContentMaxDelay(duration: Long, timeUnit: TimeUnit): Constraints.Builder
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 | |
|---|---|
duration: Long |
The length of the delay in |
timeUnit: TimeUnit |
The units of time for |
| Returns | |
|---|---|
Constraints.Builder |
The current |
setTriggerContentUpdateDelay
@RequiresApi(value = 26)
fun setTriggerContentUpdateDelay(duration: Duration): Constraints.Builder
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 | |
|---|---|
duration: Duration |
The length of the delay |
| Returns | |
|---|---|
Constraints.Builder |
The current |
setTriggerContentUpdateDelay
@RequiresApi(value = 24)
fun setTriggerContentUpdateDelay(duration: Long, timeUnit: TimeUnit): Constraints.Builder
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 | |
|---|---|
duration: Long |
The length of the delay in |
timeUnit: TimeUnit |
The units of time for |
| Returns | |
|---|---|
Constraints.Builder |
The current |