# WorkManagerScheduler

# WorkManagerScheduler

Artifact:[androidx.media3:media3-exoplayer-workmanager](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/workmanager/WorkManagerScheduler.java+class:androidx.media3.exoplayer.workmanager.WorkManagerScheduler)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/workmanager/WorkManagerScheduler "View this page in Java")

<br />

```
@UnstableApi
class WorkManagerScheduler : Scheduler
```

<br />

*** ** * ** ***

A[Scheduler](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Scheduler)that uses[WorkManager](https://developer.android.com/reference/kotlin/androidx/work/WorkManager).

## Summary

|                                                                                                                                                                                           ### Nested types                                                                                                                                                                                            |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[WorkManagerScheduler.SchedulerWorker](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/workmanager/WorkManagerScheduler.SchedulerWorker)` : `[Worker](https://developer.android.com/reference/kotlin/androidx/work/Worker) A[Worker](https://developer.android.com/reference/kotlin/androidx/work/Worker)that starts the target service if the requirements are met. |

|                                                                                                                                                                                     ### Public constructors                                                                                                                                                                                     |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [WorkManagerScheduler](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#WorkManagerScheduler(android.content.Context,java.lang.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!, workName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!)` |

|                                                ### Public functions                                                |
|--------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                | [cancel](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#cancel())`()` Cancels anything that was previously scheduled, or else does nothing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)`!` | [getSupportedRequirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#getSupportedRequirements(androidx.media3.exoplayer.scheduler.Requirements))`(requirements: `[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)`!)` Checks whether this[Scheduler](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Scheduler)supports the provided[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements).                                                                                                                                              |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                | [schedule](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#schedule(androidx.media3.exoplayer.scheduler.Requirements,java.lang.String,java.lang.String))`(` ` requirements: `[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)`!,` ` servicePackage: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!,` ` serviceAction: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` `)` Schedules a service to be started in the foreground when some[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)are met. |

## Public constructors

### WorkManagerScheduler

```
WorkManagerScheduler(context: Context!, workName: String!)
```  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`    | A context.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `workName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | A name for work scheduled by this instance. If the same name was used by a previous instance, anything scheduled by the previous instance will be canceled by this instance if[schedule](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#schedule(androidx.media3.exoplayer.scheduler.Requirements,java.lang.String,java.lang.String))or[cancel](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#cancel())are called. |

## Public functions

### cancel

```
fun cancel(): Boolean
```

Cancels anything that was previously scheduled, or else does nothing.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether cancellation was successful. |

### getSupportedRequirements

```
fun getSupportedRequirements(requirements: Requirements!): Requirements!
```

Checks whether this[Scheduler](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Scheduler)supports the provided[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements). If all of the requirements are supported then the same[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)instance is returned. If not then a new instance is returned containing the subset of the requirements that are supported.  

|                                                             Parameters                                                             |
|------------------------------------------------------------------------------------------------------------------------------------|----------------------------|
| `requirements: `[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)`!` | The requirements to check. |

|                                                      Returns                                                       |
|--------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)`!` | The supported requirements. |

### schedule

```
fun schedule(
    requirements: Requirements!,
    servicePackage: String!,
    serviceAction: String!
): Boolean
```

Schedules a service to be started in the foreground when some[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)are met. Anything that was previously scheduled will be canceled.

The service to be started must be declared in the manifest of`servicePackage`with an intent filter containing`serviceAction`. Note that when started with`
serviceAction`, the service must call[startForeground](https://developer.android.com/reference/android/app/Service.html#startForeground(int, android.app.Notification))to make itself a foreground service, as documented by[startForegroundService](https://developer.android.com/reference/android/content/ContextWrapper.html#startForegroundService(android.content.Intent)).  

|                                                             Parameters                                                             |
|------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------|
| `requirements: `[Requirements](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/Requirements)`!` | The requirements.                                  |
| `servicePackage: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                             | The package name.                                  |
| `serviceAction: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                              | The action with which the service will be started. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether scheduling was successful. |