Constraints.Builder

public static final class Constraints.Builder
extends Object

java.lang.Object
   ↳ androidx.work.Constraints.Builder


A Builder for a Constraints object.

Summary

Public constructors

Constraints.Builder()

Public methods

Constraints.Builder addContentUriTrigger(Uri uri, boolean triggerForDescendants)

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

Constraints build()

Generates the Constraints from this Builder.

Constraints.Builder setRequiredNetworkType(NetworkType networkType)

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

Constraints.Builder setRequiresBatteryNotLow(boolean requiresBatteryNotLow)

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

Constraints.Builder setRequiresCharging(boolean requiresCharging)

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

Constraints.Builder setRequiresDeviceIdle(boolean requiresDeviceIdle)

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

Constraints.Builder setRequiresStorageNotLow(boolean requiresStorageNotLow)

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

Constraints.Builder setTriggerContentMaxDelay(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.

Constraints.Builder setTriggerContentMaxDelay(long duration, 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 setTriggerContentUpdateDelay(long duration, 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 setTriggerContentUpdateDelay(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.

Inherited methods

Public constructors

Constraints.Builder

public Constraints.Builder ()

Public methods

addContentUriTrigger

public Constraints.Builder addContentUriTrigger (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
uri Uri: The local content: Uri to observe

triggerForDescendants boolean: true if any changes in descendants cause this WorkRequest to run

Returns
Constraints.Builder The current Constraints.Builder

build

public Constraints build ()

Generates the Constraints from this Builder.

Returns
Constraints The Constraints specified by this Builder

setRequiredNetworkType

public Constraints.Builder setRequiredNetworkType (NetworkType networkType)

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 Constraints.Builder

setRequiresBatteryNotLow

public 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
requiresBatteryNotLow boolean: true if the battery should be at an acceptable level for the work to run

Returns
Constraints.Builder The current Constraints.Builder

setRequiresCharging

public Constraints.Builder setRequiresCharging (boolean requiresCharging)

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

Returns
Constraints.Builder The current Constraints.Builder

setRequiresDeviceIdle

public Constraints.Builder setRequiresDeviceIdle (boolean requiresDeviceIdle)

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

Returns
Constraints.Builder The current Constraints.Builder

setRequiresStorageNotLow

public 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
requiresStorageNotLow boolean: true if the available storage should not be below a a critical threshold for the work to run

Returns
Constraints.Builder The current Constraints.Builder

setTriggerContentMaxDelay

public Constraints.Builder setTriggerContentMaxDelay (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).

Parameters
duration Duration: The length of the delay

Returns
Constraints.Builder The current Constraints.Builder

setTriggerContentMaxDelay

public Constraints.Builder setTriggerContentMaxDelay (long duration, 
                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
duration long: The length of the delay in timeUnit units

timeUnit TimeUnit: The units of time for duration

Returns
Constraints.Builder The current Constraints.Builder

setTriggerContentUpdateDelay

public Constraints.Builder setTriggerContentUpdateDelay (long duration, 
                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
duration long: The length of the delay in timeUnit units

timeUnit TimeUnit: The units of time for duration

Returns
Constraints.Builder The current Constraints.Builder

setTriggerContentUpdateDelay

public Constraints.Builder setTriggerContentUpdateDelay (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).

Parameters
duration Duration: The length of the delay

Returns
Constraints.Builder The current Constraints.Builder