Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

Constraints.Builder

public static final class Constraints.Builder
extends Object

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


Builder for Constraints class.

Summary

Public constructors

Constraints.Builder()

Public methods

Constraints.Builder addContentUriTrigger(Uri uri, boolean triggerForDescendants)

Specify whether WorkRequest should run when a content Uri is updated.

Constraints build()

Generates the Constraints from this Builder.

Constraints.Builder setRequiredNetworkType(NetworkType networkType)

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

Constraints.Builder setRequiresBatteryNotLow(boolean requiresBatteryNotLow)

Specify whether device battery should not be below critical threshold for WorkRequest to run.

Constraints.Builder setRequiresCharging(boolean requiresCharging)

Specify whether device should be plugged in for WorkRequest to run.

Constraints.Builder setRequiresDeviceIdle(boolean requiresDeviceIdle)

Specify whether device should be idle for WorkRequest to run.

Constraints.Builder setRequiresStorageNotLow(boolean requiresStorageNotLow)

Specify whether device available storage should not be below critical threshold for WorkRequest to run.

Inherited methods

Public constructors

Constraints.Builder

public Constraints.Builder ()

Public methods

addContentUriTrigger

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

Specify whether WorkRequest should run when a content Uri is updated. This method requires API 24 or higher.

Parameters
uri Uri: 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 new Constraints which can be attached to a WorkRequest

setRequiredNetworkType

public Constraints.Builder setRequiredNetworkType (NetworkType networkType)

Specify whether device should have a particular NetworkType for WorkRequest to run. Default is NetworkType.NOT_REQUIRED.

Parameters
networkType NetworkType: type of network required

Returns
Constraints.Builder current builder

setRequiresBatteryNotLow

public Constraints.Builder setRequiresBatteryNotLow (boolean requiresBatteryNotLow)

Specify whether device battery should not be below critical threshold for WorkRequest to run. Default is false.

Parameters
requiresBatteryNotLow boolean: true if battery should not be below critical threshold, false otherwise

Returns
Constraints.Builder current builder

setRequiresCharging

public Constraints.Builder setRequiresCharging (boolean requiresCharging)

Specify whether device should be plugged in for WorkRequest to run. Default is false.

Parameters
requiresCharging boolean: true if device must be plugged in, false otherwise

Returns
Constraints.Builder current builder

setRequiresDeviceIdle

public Constraints.Builder setRequiresDeviceIdle (boolean requiresDeviceIdle)

Specify whether device should be idle for WorkRequest to run. Default is false.

Parameters
requiresDeviceIdle boolean: true if device must be idle, false otherwise

Returns
Constraints.Builder current builder

setRequiresStorageNotLow

public Constraints.Builder setRequiresStorageNotLow (boolean requiresStorageNotLow)

Specify whether device available storage should not be below critical threshold for WorkRequest to run. Default is false.

Parameters
requiresStorageNotLow boolean: true if available storage should not be below critical threshold, false otherwise

Returns
Constraints.Builder current builder