Constraints
class Constraints
A specification of the requirements that need to be met before a 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 Constraints.BuilderA Builder for a |
|
This class describes a content uri trigger on the |
Public companion properties |
|
|---|---|
Constraints |
Represents a Constraints object with no requirements. |
Public constructors |
|---|
Constraints(other: Constraints) |
@IgnoreConstructs |
@IgnoreConstructs |
@IgnoreConstructs |
Public functions |
|
|---|---|
open operator Boolean |
|
open Int |
hashCode() |
Boolean |
|
Boolean |
|
Boolean |
|
Boolean |
|
open String |
toString() |
Public properties |
|
|---|---|
Long |
@ColumnInfo(name = "trigger_max_content_delay")The maximum delay in milliseconds that is allowed from the first time a |
Long |
@ColumnInfo(name = "trigger_content_update_delay")The delay in milliseconds that is allowed from the time a |
Set<Constraints.ContentUriTrigger> |
@ColumnInfo(name = "content_uri_triggers")Set of |
NetworkRequest? |
|
NetworkType |
@ColumnInfo(name = "required_network_type")The type of network required for the work to run. |
Public companion properties
Public constructors
Constraints
@Ignore
Constraints(
requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED,
requiresCharging: Boolean = false,
requiresBatteryNotLow: Boolean = false,
requiresStorageNotLow: Boolean = false
)
Constructs Constraints.
| Parameters | |
|---|---|
requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED |
The type of network required for the work to run. The default value is |
requiresCharging: Boolean = false |
whether device should be charging for the |
requiresBatteryNotLow: Boolean = false |
whether device battery should be at an acceptable level for the |
requiresStorageNotLow: Boolean = false |
whether the device's available storage should be at an acceptable level for the |
Constraints
@Ignore
Constraints(
requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED,
requiresCharging: Boolean = false,
requiresDeviceIdle: Boolean = false,
requiresBatteryNotLow: Boolean = false,
requiresStorageNotLow: Boolean = false
)
Constructs Constraints.
| Parameters | |
|---|---|
requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED |
The type of network required for the work to run. The default value is |
requiresCharging: Boolean = false |
whether device should be charging for the |
requiresDeviceIdle: Boolean = false |
whether device should be idle for the |
requiresBatteryNotLow: Boolean = false |
whether device battery should be at an acceptable level for the |
requiresStorageNotLow: Boolean = false |
whether the device's available storage should be at an acceptable level for the |
Constraints
@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 Constraints.
| Parameters | |
|---|---|
requiredNetworkType: NetworkType = NetworkType.NOT_REQUIRED |
The type of network required for the work to run. The default value is |
requiresCharging: Boolean = false |
whether device should be charging for the |
requiresDeviceIdle: Boolean = false |
whether device should be idle for the |
requiresBatteryNotLow: Boolean = false |
whether device battery should be at an acceptable level for the |
requiresStorageNotLow: Boolean = false |
whether the device's available storage should be at an acceptable level for the |
contentTriggerUpdateDelayMillis: Long = -1 |
the delay in milliseconds that is allowed from the time a |
contentTriggerMaxDelayMillis: Long = -1 |
the maximum delay in milliseconds that is allowed from the first time a |
contentUriTriggers: Set<Constraints.ContentUriTrigger> = setOf() |
set of |
Public functions
requiresBatteryNotLow
fun requiresBatteryNotLow(): Boolean
| Returns | |
|---|---|
Boolean |
|
requiresCharging
fun requiresCharging(): Boolean
| Returns | |
|---|---|
Boolean |
|
requiresDeviceIdle
fun requiresDeviceIdle(): Boolean
| Returns | |
|---|---|
Boolean |
|
requiresStorageNotLow
fun requiresStorageNotLow(): Boolean
| Returns | |
|---|---|
Boolean |
|
Public properties
contentTriggerMaxDelayMillis
@ColumnInfo(name = "trigger_max_content_delay")
val contentTriggerMaxDelayMillis: Long
The maximum delay in milliseconds that is allowed from the first time a content: Uri change is detected to the time when the WorkRequest is scheduled. This functionality is identical to the one found in JobScheduler and is described in android.app.job.JobInfo.Builder.setTriggerContentMaxDelay.
contentTriggerUpdateDelayMillis
@ColumnInfo(name = "trigger_content_update_delay")
val contentTriggerUpdateDelayMillis: Long
The delay in milliseconds that is allowed from the time a content: Uri change is detected to the time when the 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 android.app.job.JobInfo.Builder.setTriggerContentUpdateDelay
contentUriTriggers
@ColumnInfo(name = "content_uri_triggers")
val contentUriTriggers: Set<Constraints.ContentUriTrigger>
Set of ContentUriTrigger. WorkRequest will run when a local content: Uri of one of the triggers in the set is updated. This functionality is identical to the one found in JobScheduler and is described in android.app.job.JobInfo.Builder.addTriggerContentUri.
requiredNetworkRequest
val requiredNetworkRequest: NetworkRequest?
NetworkRequest required for work to run on. It is used only the API levels >= 28 (Android P). For the older API levels, 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
@ColumnInfo(name = "required_network_type")
val requiredNetworkType: NetworkType
The type of network required for the work to run.