Builder

class Builder
kotlin.Any
   ↳ androidx.work.Constraints.Builder

A Builder for a Constraints object.

Summary

Public constructors

A Builder for a Constraints object.

Public methods

Constraints.Builder
addContentUriTrigger(@NonNull uri: Uri, triggerForDescendants: Boolean)

Sets whether the WorkRequest should run when a local content: Uri is updated.

Constraints

Generates the Constraints from this Builder.

Constraints.Builder
setRequiredNetworkType(@NonNull networkType: NetworkType)

Sets whether device should have a particular NetworkType for the WorkRequest to run.

Constraints.Builder
setRequiresBatteryNotLow(requiresBatteryNotLow: Boolean)

Sets whether device battery should be at an acceptable level for the WorkRequest to run.

Constraints.Builder
setRequiresCharging(requiresCharging: Boolean)

Sets whether device should be charging for the WorkRequest to run.

Constraints.Builder
setRequiresDeviceIdle(requiresDeviceIdle: Boolean)

Sets whether device should be idle for the WorkRequest to run.

Constraints.Builder
setRequiresStorageNotLow(requiresStorageNotLow: Boolean)

Sets whether the device's available storage should be at an acceptable level for the WorkRequest to run.

Constraints.Builder
setTriggerContentMaxDelay(duration: Long, @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.

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.

Constraints.Builder
setTriggerContentUpdateDelay(duration: Long, @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.

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.

Public constructors

<init>

Builder()

A Builder for a Constraints object.

Public methods

addContentUriTrigger

@NonNull fun addContentUriTrigger(@NonNull 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 content: Uri to observe
triggerForDescendants Uri: true if any changes in descendants cause this WorkRequest to run
Return
Constraints.Builder: The current Builder

build

@NonNull fun build(): Constraints

Generates the Constraints from this Builder.

Return
Constraints: The Constraints specified by this Builder

setRequiredNetworkType

@NonNull fun setRequiredNetworkType(@NonNull 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
Return
Constraints.Builder: The current Builder

setRequiresBatteryNotLow

@NonNull 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: true if the battery should be at an acceptable level for the work to run
Return
Constraints.Builder: The current Builder

setRequiresCharging

@NonNull 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: true if device must be charging for the work to run
Return
Constraints.Builder: The current Builder

setRequiresDeviceIdle

@NonNull 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: true if device must be idle for the work to run
Return
Constraints.Builder: The current Builder

setRequiresStorageNotLow

@NonNull 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: true if the available storage should not be below a a critical threshold for the work to run
Return
Constraints.Builder: The current Builder

setTriggerContentMaxDelay

@NonNull fun setTriggerContentMaxDelay(duration: Long, @NonNull 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 units
timeUnit Long: The units of time for duration
Return
Constraints.Builder: The current Builder

setTriggerContentMaxDelay

@NonNull 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
Return
Constraints.Builder: The current Builder

setTriggerContentUpdateDelay

@NonNull fun setTriggerContentUpdateDelay(duration: Long, @NonNull 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 units
timeUnit Long: The units of time for duration
Return
Constraints.Builder: The current Builder

setTriggerContentUpdateDelay

@NonNull 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
Return
Constraints.Builder: The current Builder