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

*** ** * ** ***

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


```
@UnstableApi
class PlatformScheduler : Scheduler
```

<br />

*** ** * ** ***

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

```kotlin
<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 |
|---|
| `class `[PlatformScheduler.PlatformSchedulerService](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/PlatformScheduler.PlatformSchedulerService)` : `[JobService](https://developer.android.com/reference/android/app/job/JobService.html) A [JobService](https://developer.android.com/reference/android/app/job/JobService.html) that starts the target service if the requirements are met. |

| ### Public constructors |
|---|
| `@`[RequiresPermission](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission)`(value = `[android.Manifest.permission.RECEIVE_BOOT_COMPLETED](https://developer.android.com/reference/android/android.Manifest.permission.html#RECEIVE_BOOT_COMPLETED)`)` [PlatformScheduler](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/PlatformScheduler#PlatformScheduler(android.content.Context,int))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!, jobId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/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/scheduler/PlatformScheduler#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/scheduler/PlatformScheduler#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/scheduler/PlatformScheduler#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

### PlatformScheduler

```
@RequiresPermission(value = android.Manifest.permission.RECEIVE_BOOT_COMPLETED)
PlatformScheduler(context: Context!, jobId: Int)
```  

| Parameters |
|---|---|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!` | Any context. |
| `jobId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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 [schedule](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/PlatformScheduler#schedule(androidx.media3.exoplayer.scheduler.Requirements,java.lang.String,java.lang.String)) or [cancel](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/scheduler/PlatformScheduler#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. |