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

```
public final class Constraints
```

<br />

*** ** * ** ***

A specification of the requirements that need to be met before a `https://developer.android.com/reference/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 |
|---|
| `public final class https://developer.android.com/reference/androidx/work/Constraints.Builder` A Builder for a `https://developer.android.com/reference/androidx/work/Constraints` object. |
| `public final class https://developer.android.com/reference/androidx/work/Constraints.ContentUriTrigger` This class describes a content uri trigger on the `https://developer.android.com/reference/androidx/work/WorkRequest`: it should run when a local `content:` `https://developer.android.com/reference/android/net/Uri.html` is updated. |

| ### Public fields |
|---|---|
| `static 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#NONE()` Represents a Constraints object with no requirements. |

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

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/work/Constraints#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `final long` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24) https://developer.android.com/reference/androidx/work/Constraints#getContentTriggerMaxDelayMillis()()` 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/androidx/work/WorkRequest` is scheduled. |
| `final long` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24) https://developer.android.com/reference/androidx/work/Constraints#getContentTriggerUpdateDelayMillis()()` 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/androidx/work/WorkRequest` is scheduled. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.ContentUriTrigger>` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24) https://developer.android.com/reference/androidx/work/Constraints#getContentUriTriggers()()` Set of `https://developer.android.com/reference/androidx/work/Constraints.ContentUriTrigger`. |
| `final https://developer.android.com/reference/android/net/NetworkRequest.html` | `https://developer.android.com/reference/androidx/work/Constraints#getRequiredNetworkRequest()()` `https://developer.android.com/reference/android/net/NetworkRequest.html` required for work to run on. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/NetworkType` | `https://developer.android.com/reference/androidx/work/Constraints#getRequiredNetworkType()()` The type of network required for the work to run. |
| `int` | `https://developer.android.com/reference/androidx/work/Constraints#hashCode()()` |
| `final boolean` | `https://developer.android.com/reference/androidx/work/Constraints#requiresBatteryNotLow()()` |
| `final boolean` | `https://developer.android.com/reference/androidx/work/Constraints#requiresCharging()()` |
| `final boolean` | `https://developer.android.com/reference/androidx/work/Constraints#requiresDeviceIdle()()` |
| `final boolean` | `https://developer.android.com/reference/androidx/work/Constraints#requiresStorageNotLow()()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/work/Constraints#toString()()` |

## Public fields

### NONE

```
public static final @NonNull Constraints NONE
```

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)

```
public Constraints(@NonNull Constraints other)
```

### Constraints

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

```
@Ignore
public Constraints(
    @NonNull NetworkType requiredNetworkType,
    boolean requiresCharging,
    boolean requiresBatteryNotLow,
    boolean requiresStorageNotLow
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/NetworkType requiredNetworkType` | The type of network required for the work to run. The default value is `https://developer.android.com/reference/androidx/work/NetworkType#NOT_REQUIRED`. |
| `boolean requiresCharging` | whether device should be charging for the `https://developer.android.com/reference/androidx/work/WorkRequest` to run. The default value is `false`. |
| `boolean requiresBatteryNotLow` | 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`. |
| `boolean requiresStorageNotLow` | 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`. |

### Constraints

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

```
@Ignore
public Constraints(
    @NonNull NetworkType requiredNetworkType,
    boolean requiresCharging,
    boolean requiresDeviceIdle,
    boolean requiresBatteryNotLow,
    boolean requiresStorageNotLow
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/NetworkType requiredNetworkType` | The type of network required for the work to run. The default value is `https://developer.android.com/reference/androidx/work/NetworkType#NOT_REQUIRED`. |
| `boolean requiresCharging` | whether device should be charging for the `https://developer.android.com/reference/androidx/work/WorkRequest` to run. The default value is `false`. |
| `boolean requiresDeviceIdle` | whether device should be idle for the `https://developer.android.com/reference/androidx/work/WorkRequest` to run. The default value is `false`. |
| `boolean requiresBatteryNotLow` | 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`. |
| `boolean requiresStorageNotLow` | 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`. |

### Constraints

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

```
@Ignore
@RequiresApi(value = 24)
public Constraints(
    @NonNull NetworkType requiredNetworkType,
    boolean requiresCharging,
    boolean requiresDeviceIdle,
    boolean requiresBatteryNotLow,
    boolean requiresStorageNotLow,
    long contentTriggerUpdateDelayMillis,
    long contentTriggerMaxDelayMillis,
    @NonNull Set<@NonNull Constraints.ContentUriTrigger> contentUriTriggers
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/NetworkType requiredNetworkType` | The type of network required for the work to run. The default value is `https://developer.android.com/reference/androidx/work/NetworkType#NOT_REQUIRED`. |
| `boolean requiresCharging` | whether device should be charging for the `https://developer.android.com/reference/androidx/work/WorkRequest` to run. The default value is `false`. |
| `boolean requiresDeviceIdle` | whether device should be idle for the `https://developer.android.com/reference/androidx/work/WorkRequest` to run. The default value is `false`. |
| `boolean requiresBatteryNotLow` | 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`. |
| `boolean requiresStorageNotLow` | 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`. |
| `long 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/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)` |
| `long 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/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)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints.ContentUriTrigger> contentUriTriggers` | set of `https://developer.android.com/reference/androidx/work/Constraints.ContentUriTrigger`. `https://developer.android.com/reference/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 methods

### equals

```
public boolean equals(Object other)
```

### getContentTriggerMaxDelayMillis

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

```
@RequiresApi(value = 24)
public final long getContentTriggerMaxDelayMillis()
```

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/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)`.

### getContentTriggerUpdateDelayMillis

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

```
@RequiresApi(value = 24)
public final long getContentTriggerUpdateDelayMillis()
```

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/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)`

### getContentUriTriggers

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

```
@RequiresApi(value = 24)
public final @NonNull Set<@NonNull Constraints.ContentUriTrigger> getContentUriTriggers()
```

Set of `https://developer.android.com/reference/androidx/work/Constraints.ContentUriTrigger`. `https://developer.android.com/reference/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)`.

### getRequiredNetworkRequest

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

```
public final NetworkRequest getRequiredNetworkRequest()
```

`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/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.

### getRequiredNetworkType

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

```
public final @NonNull NetworkType getRequiredNetworkType()
```

The type of network required for the work to run.

### hashCode

```
public int hashCode()
```

### requiresBatteryNotLow

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

```
public final boolean requiresBatteryNotLow()
```

| Returns |
|---|---|
| `boolean` | `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)

```
public final boolean requiresCharging()
```

| Returns |
|---|---|
| `boolean` | `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)

```
public final boolean requiresDeviceIdle()
```

| Returns |
|---|---|
| `boolean` | `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)

```
public final boolean requiresStorageNotLow()
```

| Returns |
|---|---|
| `boolean` | `true` if the work should only execute when the storage isn't low |

### toString

```
public @NonNull String toString()
```