# Constraints

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) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

*** ** * ** ***

<br />

```
class Constraints
```

<br />

*** ** * ** ***

A specification of the requirements that need to be met before a `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` can run. By default, WorkRequests do not have any requirements and can run immediately. By adding requirements, you can make sure that work only runs in certain situations - for example, when you have an unmetered network and are charging.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/work/Constraints.Builder` A Builder for a `https://developer.android.com/reference/kotlin/androidx/work/Constraints` object. |
| `class https://developer.android.com/reference/kotlin/androidx/work/Constraints.ContentUriTrigger` This class describes a content uri trigger on the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`: it should run when a local `content:` `https://developer.android.com/reference/android/net/Uri.html` is updated. |

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Constraints` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#NONE()` Represents a Constraints object with no requirements. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Constraints#Constraints(androidx.work.Constraints)(other: https://developer.android.com/reference/kotlin/androidx/work/Constraints)` |
| `@https://developer.android.com/reference/kotlin/androidx/room/Ignore https://developer.android.com/reference/kotlin/androidx/work/Constraints#Constraints(androidx.work.NetworkType,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean)( requiredNetworkType: https://developer.android.com/reference/kotlin/androidx/work/NetworkType, requiresCharging: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, requiresBatteryNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, requiresStorageNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Constructs `https://developer.android.com/reference/kotlin/androidx/work/Constraints`. |
| `@https://developer.android.com/reference/kotlin/androidx/room/Ignore https://developer.android.com/reference/kotlin/androidx/work/Constraints#Constraints(androidx.work.NetworkType,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean)( requiredNetworkType: https://developer.android.com/reference/kotlin/androidx/work/NetworkType, requiresCharging: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, requiresDeviceIdle: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, requiresBatteryNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, requiresStorageNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Constructs `https://developer.android.com/reference/kotlin/androidx/work/Constraints`. |
| `@https://developer.android.com/reference/kotlin/androidx/room/Ignore @https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 24) https://developer.android.com/reference/kotlin/androidx/work/Constraints#Constraints(androidx.work.NetworkType,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Long,kotlin.Long,kotlin.collections.Set)( requiredNetworkType: https://developer.android.com/reference/kotlin/androidx/work/NetworkType, requiresCharging: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, requiresDeviceIdle: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, requiresBatteryNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, requiresStorageNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, contentTriggerUpdateDelayMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, contentTriggerMaxDelayMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, contentUriTriggers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/work/Constraints.ContentUriTrigger> )` Constructs `https://developer.android.com/reference/kotlin/androidx/work/Constraints`. |

| ### Public functions |
|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#requiresBatteryNotLow()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#requiresCharging()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#requiresDeviceIdle()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#requiresStorageNotLow()()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#toString()()` |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `@https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo(name = "trigger_max_content_delay") https://developer.android.com/reference/kotlin/androidx/work/Constraints#contentTriggerMaxDelayMillis()` The maximum delay in milliseconds 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/kotlin/androidx/work/WorkRequest` is scheduled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `@https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo(name = "trigger_content_update_delay") https://developer.android.com/reference/kotlin/androidx/work/Constraints#contentTriggerUpdateDelayMillis()` The delay in milliseconds 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/kotlin/androidx/work/WorkRequest` is scheduled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/work/Constraints.ContentUriTrigger>` | `@https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo(name = "content_uri_triggers") https://developer.android.com/reference/kotlin/androidx/work/Constraints#contentUriTriggers()` Set of `https://developer.android.com/reference/kotlin/androidx/work/Constraints.ContentUriTrigger`. |
| `https://developer.android.com/reference/android/net/NetworkRequest.html?` | `https://developer.android.com/reference/kotlin/androidx/work/Constraints#requiredNetworkRequest()` `https://developer.android.com/reference/android/net/NetworkRequest.html` required for work to run on. |
| `https://developer.android.com/reference/kotlin/androidx/work/NetworkType` | `@https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo(name = "required_network_type") https://developer.android.com/reference/kotlin/androidx/work/Constraints#requiredNetworkType()` The type of network required for the work to run. |

## Public companion properties

### NONE

```
val NONE: Constraints
```

Represents a Constraints object with no requirements.

## Public constructors

### Constraints

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

```
Constraints(other: Constraints)
```

### Constraints

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

```
@Ignore
Constraints(
    requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED,
    requiresCharging: Boolean = false,
    requiresBatteryNotLow: Boolean = false,
    requiresStorageNotLow: Boolean = false
)
```

Constructs `https://developer.android.com/reference/kotlin/androidx/work/Constraints`.

| Parameters |
|---|---|
| `requiredNetworkType: https://developer.android.com/reference/kotlin/androidx/work/NetworkType = NetworkType.NOT_REQUIRED` | The type of network required for the work to run. The default value is `https://developer.android.com/reference/kotlin/androidx/work/NetworkType#NOT_REQUIRED`. |
| `requiresCharging: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether device should be charging for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `requiresBatteryNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether device battery should be at an acceptable level for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `requiresStorageNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether the device's available storage should be at an acceptable level for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |

### Constraints

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

```
@Ignore
Constraints(
    requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED,
    requiresCharging: Boolean = false,
    requiresDeviceIdle: Boolean = false,
    requiresBatteryNotLow: Boolean = false,
    requiresStorageNotLow: Boolean = false
)
```

Constructs `https://developer.android.com/reference/kotlin/androidx/work/Constraints`.

| Parameters |
|---|---|
| `requiredNetworkType: https://developer.android.com/reference/kotlin/androidx/work/NetworkType = NetworkType.NOT_REQUIRED` | The type of network required for the work to run. The default value is `https://developer.android.com/reference/kotlin/androidx/work/NetworkType#NOT_REQUIRED`. |
| `requiresCharging: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether device should be charging for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `requiresDeviceIdle: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether device should be idle for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `requiresBatteryNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether device battery should be at an acceptable level for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `requiresStorageNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether the device's available storage should be at an acceptable level for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |

### Constraints

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

```
@Ignore
@RequiresApi(value = 24)
Constraints(
    requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED,
    requiresCharging: Boolean = false,
    requiresDeviceIdle: Boolean = false,
    requiresBatteryNotLow: Boolean = false,
    requiresStorageNotLow: Boolean = false,
    contentTriggerUpdateDelayMillis: Long = -1,
    contentTriggerMaxDelayMillis: Long = -1,
    contentUriTriggers: Set<Constraints.ContentUriTrigger> = setOf()
)
```

Constructs `https://developer.android.com/reference/kotlin/androidx/work/Constraints`.

| Parameters |
|---|---|
| `requiredNetworkType: https://developer.android.com/reference/kotlin/androidx/work/NetworkType = NetworkType.NOT_REQUIRED` | The type of network required for the work to run. The default value is `https://developer.android.com/reference/kotlin/androidx/work/NetworkType#NOT_REQUIRED`. |
| `requiresCharging: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether device should be charging for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `requiresDeviceIdle: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether device should be idle for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `requiresBatteryNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether device battery should be at an acceptable level for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `requiresStorageNotLow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | whether the device's available storage should be at an acceptable level for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to run. The default value is `false`. |
| `contentTriggerUpdateDelayMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = -1` | the delay in milliseconds 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/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 `https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setTriggerContentUpdateDelay(long)` |
| `contentTriggerMaxDelayMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = -1` | the maximum delay in milliseconds 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/kotlin/androidx/work/WorkRequest` is scheduled. This functionality is identical to the one found in `JobScheduler` and is described in `https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setTriggerContentMaxDelay(long)`. |
| `contentUriTriggers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/work/Constraints.ContentUriTrigger> = setOf()` | set of `https://developer.android.com/reference/kotlin/androidx/work/Constraints.ContentUriTrigger`. `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` will run when a local `content:` `https://developer.android.com/reference/android/net/Uri.html` of one of the triggers in the set is updated. This functionality is identical to the one found in `JobScheduler` and is described in `https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)`. |

## Public functions

### equals

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

```
open fun hashCode(): Int
```

### requiresBatteryNotLow

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

```
fun requiresBatteryNotLow(): Boolean
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the work should only execute when the battery isn't low |

### requiresCharging

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

```
fun requiresCharging(): Boolean
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the work should only execute while the device is charging |

### requiresDeviceIdle

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

```
fun requiresDeviceIdle(): Boolean
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the work should only execute while the device is idle |

### requiresStorageNotLow

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

```
fun requiresStorageNotLow(): Boolean
```

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the work should only execute when the storage isn't low |

### toString

```
open fun toString(): String
```

## Public properties

### contentTriggerMaxDelayMillis

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

```
@ColumnInfo(name = "trigger_max_content_delay")
val contentTriggerMaxDelayMillis: Long
```

The maximum delay in milliseconds 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/kotlin/androidx/work/WorkRequest` is scheduled. This functionality is identical to the one found in `JobScheduler` and is described in `https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setTriggerContentMaxDelay(long)`.

### contentTriggerUpdateDelayMillis

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

```
@ColumnInfo(name = "trigger_content_update_delay")
val contentTriggerUpdateDelayMillis: Long
```

The delay in milliseconds 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/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 `https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setTriggerContentUpdateDelay(long)`

### contentUriTriggers

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

```
@ColumnInfo(name = "content_uri_triggers")
val contentUriTriggers: Set<Constraints.ContentUriTrigger>
```

Set of `https://developer.android.com/reference/kotlin/androidx/work/Constraints.ContentUriTrigger`. `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` will run when a local `content:` `https://developer.android.com/reference/android/net/Uri.html` of one of the triggers in the set is updated. This functionality is identical to the one found in `JobScheduler` and is described in `https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#addTriggerContentUri(android.app.job.JobInfo.TriggerContentUri)`.

### requiredNetworkRequest

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

```
val requiredNetworkRequest: NetworkRequest?
```

`https://developer.android.com/reference/android/net/NetworkRequest.html` required for work to run on. It is used only the API levels \>= 28 (Android P). For the older API levels, `https://developer.android.com/reference/kotlin/androidx/work/Constraints#requiredNetworkType()` will be used instead on the older platforms and this property will be `null`.

`NetworkRequest`-s with `NetworkSpecifier` set aren't supported, as well as `NetworkRequest` with `setIncludeOtherUidNetworks` set. passed.

### requiredNetworkType

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

```
@ColumnInfo(name = "required_network_type")
val requiredNetworkType: NetworkType
```

The type of network required for the work to run.