public final class

Constraints.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.work.Constraints.Builder

Overview

A Builder for a Constraints object.

Summary

Constructors
publicBuilder()

Methods
public Constraints.BuilderaddContentUriTrigger(Uri uri, boolean triggerForDescendants)

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

public Constraintsbuild()

Generates the Constraints from this Builder.

public Constraints.BuildersetRequiredNetworkType(NetworkType networkType)

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

public Constraints.BuildersetRequiresBatteryNotLow(boolean requiresBatteryNotLow)

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

public Constraints.BuildersetRequiresCharging(boolean requiresCharging)

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

public Constraints.BuildersetRequiresDeviceIdle(boolean requiresDeviceIdle)

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

public Constraints.BuildersetRequiresStorageNotLow(boolean requiresStorageNotLow)

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

public Constraints.BuildersetTriggerContentMaxDelay(java.time.Duration duration)

Sets the maximum delay that is allowed from the first time a content: change is detected to the time when the WorkRequest is scheduled.

public Constraints.BuildersetTriggerContentMaxDelay(long duration, java.util.concurrent.TimeUnit timeUnit)

Sets the maximum delay that is allowed from the first time a content: change is detected to the time when the WorkRequest is scheduled.

public Constraints.BuildersetTriggerContentUpdateDelay(java.time.Duration duration)

Sets the delay that is allowed from the time a content: change is detected to the time when the WorkRequest is scheduled.

public Constraints.BuildersetTriggerContentUpdateDelay(long duration, java.util.concurrent.TimeUnit timeUnit)

Sets the delay that is allowed from the time a content: change is detected to the time when the WorkRequest is scheduled.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Methods

public Constraints.Builder setRequiresCharging(boolean requiresCharging)

Sets whether device should be charging for the WorkRequest to run. The default value is false.

Parameters:

requiresCharging: true if device must be charging for the work to run

Returns:

The current Constraints.Builder

public Constraints.Builder setRequiresDeviceIdle(boolean requiresDeviceIdle)

Sets whether device should be idle for the WorkRequest to run. The default value is false.

Parameters:

requiresDeviceIdle: true if device must be idle for the work to run

Returns:

The current Constraints.Builder

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: The type of network required for the work to run

Returns:

The current Constraints.Builder

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

Returns:

The current Constraints.Builder

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

Returns:

The current Constraints.Builder

public Constraints.Builder addContentUriTrigger(Uri uri, boolean triggerForDescendants)

Sets whether the WorkRequest should run when a local content: 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: The local content: Uri to observe
triggerForDescendants: true if any changes in descendants cause this WorkRequest to run

Returns:

The current Constraints.Builder

public Constraints.Builder setTriggerContentUpdateDelay(long duration, java.util.concurrent.TimeUnit timeUnit)

Sets the delay that is allowed from the time a content: 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: The length of the delay in timeUnit units
timeUnit: The units of time for duration

Returns:

The current Constraints.Builder

public Constraints.Builder setTriggerContentUpdateDelay(java.time.Duration duration)

Sets the delay that is allowed from the time a content: 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: The length of the delay

Returns:

The current Constraints.Builder

public Constraints.Builder setTriggerContentMaxDelay(long duration, java.util.concurrent.TimeUnit timeUnit)

Sets the maximum delay that is allowed from the first time a content: 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: The length of the delay in timeUnit units
timeUnit: The units of time for duration

Returns:

The current Constraints.Builder

public Constraints.Builder setTriggerContentMaxDelay(java.time.Duration duration)

Sets the maximum delay that is allowed from the first time a content: 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: The length of the delay

Returns:

The current Constraints.Builder

public Constraints build()

Generates the Constraints from this Builder.

Returns:

The Constraints specified by this Builder