PlatformScheduler

@RequiresApi(value = 21)
@UnstableApi
class PlatformScheduler : Scheduler


A Scheduler that uses JobScheduler. To use this scheduler, you must add 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

A JobService that starts the target service if the requirements are met.

Public constructors

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

Public functions

Boolean

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

Requirements!

Checks whether this Scheduler supports the provided Requirements.

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

Schedules a service to be started in the foreground when some Requirements are met.

Public constructors

PlatformScheduler

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

Any context.

jobId: Int

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 or cancel are called.

Public functions

cancel

fun cancel(): Boolean

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

Returns
Boolean

Whether cancellation was successful.

getSupportedRequirements

fun getSupportedRequirements(requirements: Requirements!): Requirements!

Checks whether this Scheduler supports the provided Requirements. If all of the requirements are supported then the same Requirements instance is returned. If not then a new instance is returned containing the subset of the requirements that are supported.

Parameters
requirements: Requirements!

The requirements to check.

Returns
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 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 to make itself a foreground service, as documented by startForegroundService.

Parameters
requirements: Requirements!

The requirements.

servicePackage: String!

The package name.

serviceAction: String!

The action with which the service will be started.

Returns
Boolean

Whether scheduling was successful.