Builder

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

Builder for Constraints class.

Summary

Public constructors

Public methods
Constraints.Builder!
addContentUriTrigger(uri: Uri!, triggerForDescendants: Boolean)

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

Constraints.Builder!
setRequiresCharging(requiresCharging: Boolean)

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

Constraints.Builder!
setRequiresDeviceIdle(requiresDeviceIdle: Boolean)

Specify whether device should be idle for WorkRequest to run.

Constraints.Builder!
setRequiresStorageNotLow(requiresStorageNotLow: Boolean)

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

Constraints.Builder!

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

Constraints.Builder!
setRequiresBatteryNotLow(requiresBatteryNotLow: Boolean)

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

Constraints!

Generates the Constraints from this Builder.

Public constructors

<init>

Builder()

Public methods

addContentUriTrigger

fun addContentUriTrigger(uri: Uri!, triggerForDescendants: Boolean): Constraints.Builder!

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

Parameters
uri Uri!: android.net.Uri to observe
triggerForDescendants Uri!: true if any changes in descendants cause this WorkRequest to run
Return
Constraints.Builder!: The current Builder

setRequiresCharging

fun setRequiresCharging(requiresCharging: Boolean): Constraints.Builder!

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
Return
Constraints.Builder!: current builder

setRequiresDeviceIdle

fun setRequiresDeviceIdle(requiresDeviceIdle: Boolean): Constraints.Builder!

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

Parameters
requiresDeviceIdle Boolean: true if device must be idle, false otherwise
Return
Constraints.Builder!: current builder

setRequiresStorageNotLow

fun setRequiresStorageNotLow(requiresStorageNotLow: Boolean): Constraints.Builder!

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
Return
Constraints.Builder!: current builder

setRequiredNetworkType

fun setRequiredNetworkType(networkType: NetworkType): Constraints.Builder!

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

Parameters
networkType NetworkType: type of network required
Return
Constraints.Builder!: current builder

setRequiresBatteryNotLow

fun setRequiresBatteryNotLow(requiresBatteryNotLow: Boolean): Constraints.Builder!

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
Return
Constraints.Builder!: current builder

build

fun build(): Constraints!

Generates the Constraints from this Builder.

Return
Constraints!: new Constraints which can be attached to a WorkRequest