# Constraints.Builder

# Constraints.Builder

Artifact: [androidx.work:work-runtime](https://developer.android.com/jetpack/androidx/releases/work)  
[View Source](https://cs.android.com/search?q=file:androidx/work/Constraints.kt+class:androidx.work.Constraints.Builder)  
Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/work/Constraints.Builder "View this page in Java")


```
class Constraints.Builder
```

<br />

*** ** * ** ***

A Builder for a [Constraints](https://developer.android.com/reference/kotlin/androidx/work/Constraints) object.

## Summary

|                                          ### Public constructors                                          |
|-----------------------------------------------------------------------------------------------------------|
| [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#Builder())`()` |

|                                          ### Public functions                                           |
|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 24)` [addContentUriTrigger](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#addContentUriTrigger(android.net.Uri,kotlin.Boolean))`(uri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)`, triggerForDescendants: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) should run when a local `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) is updated.                                                                                         |
| [Constraints](https://developer.android.com/reference/kotlin/androidx/work/Constraints)                 | [build](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#build())`()` Generates the [Constraints](https://developer.android.com/reference/kotlin/androidx/work/Constraints) from this Builder.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | [setRequiredNetworkRequest](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setRequiredNetworkRequest(android.net.NetworkRequest,androidx.work.NetworkType))`(` ` networkRequest: `[NetworkRequest](https://developer.android.com/reference/android/net/NetworkRequest.html)`,` ` networkType: `[NetworkType](https://developer.android.com/reference/kotlin/androidx/work/NetworkType) `)` Sets whether device should have a particular [NetworkRequest](https://developer.android.com/reference/android/net/NetworkRequest.html) for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run on the API levels \>= 28 (Android P).                                                                             |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | [setRequiredNetworkType](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setRequiredNetworkType(androidx.work.NetworkType))`(networkType: `[NetworkType](https://developer.android.com/reference/kotlin/androidx/work/NetworkType)`)` Sets whether device should have a particular [NetworkType](https://developer.android.com/reference/kotlin/androidx/work/NetworkType) for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run.                                                                                                                                                                                                                                                                          |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | [setRequiresBatteryNotLow](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setRequiresBatteryNotLow(kotlin.Boolean))`(requiresBatteryNotLow: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether device battery should be at an acceptable level for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run.                                                                                                                                                                                                                                                                                                                                                   |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | [setRequiresCharging](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setRequiresCharging(kotlin.Boolean))`(requiresCharging: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether device should be charging for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run.                                                                                                                                                                                                                                                                                                                                                                                        |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | [setRequiresDeviceIdle](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setRequiresDeviceIdle(kotlin.Boolean))`(requiresDeviceIdle: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether device should be idle for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run.                                                                                                                                                                                                                                                                                                                                                                                      |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | [setRequiresStorageNotLow](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setRequiresStorageNotLow(kotlin.Boolean))`(requiresStorageNotLow: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether the device's available storage should be at an acceptable level for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run.                                                                                                                                                                                                                                                                                                                                   |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 26)` [setTriggerContentMaxDelay](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setTriggerContentMaxDelay(java.time.Duration))`(duration: `[Duration](https://developer.android.com/reference/java/time/Duration.html)`)` Sets the maximum delay that is allowed from the first time a `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) change is detected to the time when the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) is scheduled.                                                                                                                              |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 24)` [setTriggerContentMaxDelay](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setTriggerContentMaxDelay(kotlin.Long,java.util.concurrent.TimeUnit))`(duration: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, timeUnit: `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit.html)`)` Sets the maximum delay that is allowed from the first time a `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) change is detected to the time when the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) is scheduled. |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 26)` [setTriggerContentUpdateDelay](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setTriggerContentUpdateDelay(java.time.Duration))`(duration: `[Duration](https://developer.android.com/reference/java/time/Duration.html)`)` Sets the delay that is allowed from the time a `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) change is detected to the time when the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) is scheduled.                                                                                                                                      |
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 24)` [setTriggerContentUpdateDelay](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder#setTriggerContentUpdateDelay(kotlin.Long,java.util.concurrent.TimeUnit))`(duration: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, timeUnit: `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit.html)`)` Sets the delay that is allowed from the time a `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) change is detected to the time when the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) is scheduled.         |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

```
Builder()
```  

## Public functions

### addContentUriTrigger

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

```
@RequiresApi(value = 24)
fun addContentUriTrigger(uri: Uri, triggerForDescendants: Boolean): Constraints.Builder
```

Sets whether the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) should run when a local `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) 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](https://developer.android.com/reference/android/net/Uri.html)                                   | The local `content:` Uri to observe                                                                                                            |
| `triggerForDescendants: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true` if any changes in descendants cause this [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

```
fun build(): Constraints
```

Generates the [Constraints](https://developer.android.com/reference/kotlin/androidx/work/Constraints) from this Builder.  

|                                         Returns                                         |
|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| [Constraints](https://developer.android.com/reference/kotlin/androidx/work/Constraints) | The [Constraints](https://developer.android.com/reference/kotlin/androidx/work/Constraints) specified by this Builder |

### setRequiredNetworkRequest

Added in [2.10.0](https://developer.android.com/jetpack/androidx/releases/work#2.10.0)  

```
fun setRequiredNetworkRequest(
    networkRequest: NetworkRequest,
    networkType: NetworkType
): Constraints.Builder
```

Sets whether device should have a particular [NetworkRequest](https://developer.android.com/reference/android/net/NetworkRequest.html) for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run on the API levels \>= 28 (Android P). For the older API levels, `networkType` will be used instead on the older platforms.

`NetworkRequest` with `NetworkSpecifier` set aren't supported, as well as `NetworkRequest` with `setIncludeOtherUidNetworks` set. [IllegalArgumentException](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html) will be thrown if such requests are passed.  

|                                                 Parameters                                                  |
|-------------------------------------------------------------------------------------------------------------|------------------------------------|
| `networkRequest: `[NetworkRequest](https://developer.android.com/reference/android/net/NetworkRequest.html) |                                    |
| `networkType: `[NetworkType](https://developer.android.com/reference/kotlin/androidx/work/NetworkType)      | The type of network required for t |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setRequiredNetworkType

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

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

Sets whether device should have a particular [NetworkType](https://developer.android.com/reference/kotlin/androidx/work/NetworkType) for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run. The default value is [NetworkType.NOT_REQUIRED](https://developer.android.com/reference/kotlin/androidx/work/NetworkType#NOT_REQUIRED).  

|                                               Parameters                                               |
|--------------------------------------------------------------------------------------------------------|--------------------------------------------------|
| `networkType: `[NetworkType](https://developer.android.com/reference/kotlin/androidx/work/NetworkType) | The type of network required for the work to run |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setRequiresBatteryNotLow

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

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

Sets whether device battery should be at an acceptable level for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run. The default value is `false`.  

|                                                  Parameters                                                  |
|--------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
| `requiresBatteryNotLow: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true` if the battery should be at an acceptable level for the work to run |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setRequiresCharging

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

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

Sets whether device should be charging for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run. The default value is `false`.  

|                                               Parameters                                                |
|---------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| `requiresCharging: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true` if device must be charging for the work to run |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setRequiresDeviceIdle

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

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

Sets whether device should be idle for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run. The default value is `false`.  

|                                                Parameters                                                 |
|-----------------------------------------------------------------------------------------------------------|---------------------------------------------------|
| `requiresDeviceIdle: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true` if device must be idle for the work to run |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setRequiresStorageNotLow

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

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

Sets whether the device's available storage should be at an acceptable level for the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) to run. The default value is `false`.  

|                                                  Parameters                                                  |
|--------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| `requiresStorageNotLow: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true` if the available storage should not be below a a critical threshold for the work to run |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setTriggerContentMaxDelay

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

```
@RequiresApi(value = 26)
fun setTriggerContentMaxDelay(duration: Duration): Constraints.Builder
```

Sets the maximum delay that is allowed from the first time a `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) change is detected to the time when the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) is scheduled. This functionality is identical to the one found in `JobScheduler` and is described in `JobInfo.Builder#setTriggerContentMaxDelay(long)`.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|-------------------------|
| `duration: `[Duration](https://developer.android.com/reference/java/time/Duration.html) | The length of the delay |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setTriggerContentMaxDelay

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

```
@RequiresApi(value = 24)
fun setTriggerContentMaxDelay(duration: Long, timeUnit: TimeUnit): Constraints.Builder
```

Sets the maximum delay that is allowed from the first time a `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) change is detected to the time when the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest) is scheduled. This functionality is identical to the one found in `JobScheduler` and is described in `JobInfo.Builder#setTriggerContentMaxDelay(long)`.  

|                                             Parameters                                             |
|----------------------------------------------------------------------------------------------------|---------------------------------------------|
| `duration: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)          | The length of the delay in `timeUnit` units |
| `timeUnit: `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit.html) | The units of time for `duration`            |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setTriggerContentUpdateDelay

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

```
@RequiresApi(value = 26)
fun setTriggerContentUpdateDelay(duration: Duration): Constraints.Builder
```

Sets the delay that is allowed from the time a `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) change is detected to the time when the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/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](https://developer.android.com/reference/java/time/Duration.html) | The length of the delay |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |

### setTriggerContentUpdateDelay

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)  

```
@RequiresApi(value = 24)
fun setTriggerContentUpdateDelay(duration: Long, timeUnit: TimeUnit): Constraints.Builder
```

Sets the delay that is allowed from the time a `content:` [Uri](https://developer.android.com/reference/android/net/Uri.html) change is detected to the time when the [WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)          | The length of the delay in `timeUnit` units |
| `timeUnit: `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit.html) | The units of time for `duration`            |

|                                                 Returns                                                 |
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [Constraints.Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) | The current [Builder](https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder) |