# 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)

*** ** * ** ***


```
public final class Constraints.Builder
```

<br />

*** ** * ** ***

A Builder for a `https://developer.android.com/reference/androidx/work/Constraints` object.

## Summary

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

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

## Public constructors

### Builder

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

```
public Builder()
```

## Public methods

### addContentUriTrigger

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

```
@RequiresApi(value = 24)
public final @NonNull Constraints.Builder addContentUriTrigger(@NonNull Uri uri, boolean triggerForDescendants)
```

Sets whether the `https://developer.android.com/reference/androidx/work/WorkRequest` should run when a local `content:` `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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html uri` | The local `content:` Uri to observe |
| `boolean triggerForDescendants` | `true` if any changes in descendants cause this `https://developer.android.com/reference/androidx/work/WorkRequest` to run |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### build

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

```
public final @NonNull Constraints build()
```

Generates the `https://developer.android.com/reference/androidx/work/Constraints` from this Builder.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints` | The `https://developer.android.com/reference/androidx/work/Constraints` specified by this Builder |

### setRequiredNetworkRequest

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

```
public final @NonNull Constraints.Builder setRequiredNetworkRequest(
    @NonNull NetworkRequest networkRequest,
    @NonNull NetworkType networkType
)
```

Sets whether device should have a particular `https://developer.android.com/reference/android/net/NetworkRequest.html` for the `https://developer.android.com/reference/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. `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` will be thrown if such requests are passed.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/NetworkRequest.html networkRequest` |   |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/NetworkType networkType` | The type of network required for t |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setRequiredNetworkType

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

```
public final @NonNull Constraints.Builder setRequiredNetworkType(@NonNull NetworkType networkType)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/NetworkType networkType` | The type of network required for the work to run |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setRequiresBatteryNotLow

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

```
public final @NonNull Constraints.Builder setRequiresBatteryNotLow(boolean requiresBatteryNotLow)
```

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

| Parameters |
|---|---|
| `boolean requiresBatteryNotLow` | `true` if the battery should be at an acceptable level for the work to run |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setRequiresCharging

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

```
public final @NonNull Constraints.Builder setRequiresCharging(boolean requiresCharging)
```

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

| Parameters |
|---|---|
| `boolean requiresCharging` | `true` if device must be charging for the work to run |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setRequiresDeviceIdle

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

```
public final @NonNull Constraints.Builder setRequiresDeviceIdle(boolean requiresDeviceIdle)
```

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

| Parameters |
|---|---|
| `boolean requiresDeviceIdle` | `true` if device must be idle for the work to run |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setRequiresStorageNotLow

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

```
public final @NonNull Constraints.Builder setRequiresStorageNotLow(boolean requiresStorageNotLow)
```

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

| Parameters |
|---|---|
| `boolean requiresStorageNotLow` | `true` if the available storage should not be below a a critical threshold for the work to run |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setTriggerContentMaxDelay

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

```
@RequiresApi(value = 26)
public final @NonNull Constraints.Builder setTriggerContentMaxDelay(@NonNull Duration duration)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/time/Duration.html duration` | The length of the delay |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setTriggerContentMaxDelay

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

```
@RequiresApi(value = 24)
public final @NonNull Constraints.Builder setTriggerContentMaxDelay(long duration, @NonNull TimeUnit timeUnit)
```

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

| Parameters |
|---|---|
| `long duration` | The length of the delay in `timeUnit` units |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/TimeUnit.html timeUnit` | The units of time for `duration` |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setTriggerContentUpdateDelay

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

```
@RequiresApi(value = 26)
public final @NonNull Constraints.Builder setTriggerContentUpdateDelay(@NonNull Duration duration)
```

Sets the delay that is allowed from the time a `content:` `https://developer.android.com/reference/android/net/Uri.html` change is detected to the time when the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/time/Duration.html duration` | The length of the delay |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |

### setTriggerContentUpdateDelay

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

```
@RequiresApi(value = 24)
public final @NonNull Constraints.Builder setTriggerContentUpdateDelay(long duration, @NonNull TimeUnit timeUnit)
```

Sets the delay that is allowed from the time a `content:` `https://developer.android.com/reference/android/net/Uri.html` change is detected to the time when the `https://developer.android.com/reference/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 |
|---|---|
| `long duration` | The length of the delay in `timeUnit` units |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/TimeUnit.html timeUnit` | The units of time for `duration` |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.Builder` | The current `https://developer.android.com/reference/androidx/work/Constraints.Builder` |