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

*** ** * ** ***


```
@UnstableApi
public final class WorkManagerScheduler implements Scheduler
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Scheduler` that uses `https://developer.android.com/reference/androidx/work/WorkManager`.

## Summary

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

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#WorkManagerScheduler(android.content.Context,java.lang.String)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/String.html workName)` |

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

## Public constructors

### WorkManagerScheduler

```
public WorkManagerScheduler(Context context, String workName)
```

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A context. |
| `https://developer.android.com/reference/java/lang/String.html workName` | 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 `https://developer.android.com/reference/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#schedule(androidx.media3.exoplayer.scheduler.Requirements,java.lang.String,java.lang.String)` or `https://developer.android.com/reference/androidx/media3/exoplayer/workmanager/WorkManagerScheduler#cancel()` are called. |

## Public methods

### cancel

```
public boolean cancel()
```

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

| Returns |
|---|---|
| `boolean` | Whether cancellation was successful. |

### getSupportedRequirements

```
public Requirements getSupportedRequirements(Requirements requirements)
```

Checks whether this `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Scheduler` supports the provided `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements`. If all of the requirements are supported then the same `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements requirements` | The requirements to check. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements` | The supported requirements. |

### schedule

```
public boolean schedule(
    Requirements requirements,
    String servicePackage,
    String serviceAction
)
```

Schedules a service to be started in the foreground when some `https://developer.android.com/reference/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 `https://developer.android.com/reference/android/app/Service.html#startForeground(int, android.app.Notification)` to make itself a foreground service, as documented by `https://developer.android.com/reference/android/content/ContextWrapper.html#startForegroundService(android.content.Intent)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Requirements requirements` | The requirements. |
| `https://developer.android.com/reference/java/lang/String.html servicePackage` | The package name. |
| `https://developer.android.com/reference/java/lang/String.html serviceAction` | The action with which the service will be started. |

| Returns |
|---|---|
| `boolean` | Whether scheduling was successful. |