Constraints
public final 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 |
---|
public final class Constraints.Builder A Builder for a |
public final class Constraints.ContentUriTrigger This class describes a content uri trigger on the |
Public fields |
|
---|---|
static final @NonNull Constraints |
Represents a Constraints object with no requirements. |
Public constructors |
---|
Constraints(@NonNull Constraints other) |
Constraints( Constructs |
@RequiresApi(value = 23) Constructs |
@RequiresApi(value = 24) Constructs |
Public methods |
|
---|---|
boolean |
|
final long |
@RequiresApi(value = 24) The maximum delay in milliseconds that is allowed from the first time a |
final long |
@RequiresApi(value = 24) The delay in milliseconds that is allowed from the time a |
final @NonNull Set<@NonNull Constraints.ContentUriTrigger> |
@RequiresApi(value = 24) Set of |
final NetworkRequest |
@RequiresApi(value = 21)
|
final @NonNull NetworkType |
The type of network required for the work to run. |
int |
hashCode() |
final boolean |
|
final boolean |
|
final boolean |
@RequiresApi(value = 23) |
final boolean |
|
@NonNull String |
toString() |
Public fields
NONE
public static final @NonNull Constraints NONE
Represents a Constraints object with no requirements.
Public constructors
Constraints
public Constraints(
@NonNull NetworkType requiredNetworkType,
boolean requiresCharging,
boolean requiresBatteryNotLow,
boolean requiresStorageNotLow
)
Constructs Constraints
.
Parameters | |
---|---|
@NonNull NetworkType requiredNetworkType |
The type of network required for the work to run. The default value is |
boolean requiresCharging |
whether device should be charging for the |
boolean requiresBatteryNotLow |
whether device battery should be at an acceptable level for the |
boolean requiresStorageNotLow |
whether the device's available storage should be at an acceptable level for the |
Constraints
@RequiresApi(value = 23)
public Constraints(
@NonNull NetworkType requiredNetworkType,
boolean requiresCharging,
boolean requiresDeviceIdle,
boolean requiresBatteryNotLow,
boolean requiresStorageNotLow
)
Constructs Constraints
.
Parameters | |
---|---|
@NonNull NetworkType requiredNetworkType |
The type of network required for the work to run. The default value is |
boolean requiresCharging |
whether device should be charging for the |
boolean requiresDeviceIdle |
whether device should be idle for the |
boolean requiresBatteryNotLow |
whether device battery should be at an acceptable level for the |
boolean requiresStorageNotLow |
whether the device's available storage should be at an acceptable level for the |
Constraints
@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 Constraints
.
Parameters | |
---|---|
@NonNull NetworkType requiredNetworkType |
The type of network required for the work to run. The default value is |
boolean requiresCharging |
whether device should be charging for the |
boolean requiresDeviceIdle |
whether device should be idle for the |
boolean requiresBatteryNotLow |
whether device battery should be at an acceptable level for the |
boolean requiresStorageNotLow |
whether the device's available storage should be at an acceptable level for the |
long contentTriggerUpdateDelayMillis |
the delay in milliseconds that is allowed from the time a |
long contentTriggerMaxDelayMillis |
the maximum delay in milliseconds that is allowed from the first time a |
@NonNull Set<@NonNull Constraints.ContentUriTrigger> contentUriTriggers |
set of |
Public methods
getContentTriggerMaxDelayMillis
@RequiresApi(value = 24)
public final long getContentTriggerMaxDelayMillis()
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
.
getContentTriggerUpdateDelayMillis
@RequiresApi(value = 24)
public final long getContentTriggerUpdateDelayMillis()
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
getContentUriTriggers
@RequiresApi(value = 24)
public final @NonNull Set<@NonNull Constraints.ContentUriTrigger> getContentUriTriggers()
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
.
getRequiredNetworkRequest
@RequiresApi(value = 21)
public final NetworkRequest getRequiredNetworkRequest()
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.
getRequiredNetworkType
public final @NonNull NetworkType getRequiredNetworkType()
The type of network required for the work to run.
requiresBatteryNotLow
public final boolean requiresBatteryNotLow()
Returns | |
---|---|
boolean |
|
requiresCharging
public final boolean requiresCharging()
Returns | |
---|---|
boolean |
|
requiresDeviceIdle
@RequiresApi(value = 23)
public final boolean requiresDeviceIdle()
Returns | |
---|---|
boolean |
|
requiresStorageNotLow
public final boolean requiresStorageNotLow()
Returns | |
---|---|
boolean |
|