# PlatformScheduler

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

*** ** * ** ***


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

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/Scheduler` that uses `https://developer.android.com/reference/android/app/job/JobScheduler.html`. To use this scheduler, you must add `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/PlatformScheduler.PlatformSchedulerService` to your manifest:

```
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<service android:name="androidx.media3.exoplayer.scheduler.PlatformScheduler$PlatformSchedulerService"
    android:permission="android.permission.BIND_JOB_SERVICE"
    android:exported="true"/>
```

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/PlatformScheduler.PlatformSchedulerService extends https://developer.android.com/reference/android/app/job/JobService.html` A `https://developer.android.com/reference/android/app/job/JobService.html` that starts the target service if the requirements are met. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/androidx/annotation/RequiresPermission(value = https://developer.android.com/reference/android/android.Manifest.permission.html#RECEIVE_BOOT_COMPLETED) https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/PlatformScheduler#PlatformScheduler(android.content.Context,int)(https://developer.android.com/reference/android/content/Context.html context, int jobId)` |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/PlatformScheduler#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/scheduler/PlatformScheduler#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/scheduler/PlatformScheduler#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

### PlatformScheduler

```
@RequiresPermission(value = android.Manifest.permission.RECEIVE_BOOT_COMPLETED)
public PlatformScheduler(Context context, int jobId)
```

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | Any context. |
| `int jobId` | An identifier for the jobs scheduled by this instance. If the same identifier 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/scheduler/PlatformScheduler#schedule(androidx.media3.exoplayer.scheduler.Requirements,java.lang.String,java.lang.String)` or `https://developer.android.com/reference/androidx/media3/exoplayer/scheduler/PlatformScheduler#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. |