Package com.google.android.exoplayer2.scheduler

## Class PlatformScheduler

- java.lang.Object
- - com.google.android.exoplayer2.scheduler.PlatformScheduler

- All Implemented Interfaces:
    `Scheduler`

      @RequiresApi(21)
      public final class PlatformScheduler
      extends Object
      implements Scheduler

  A `Scheduler` that uses `JobScheduler`. To use this scheduler, you must add `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="com.google.android.exoplayer2.scheduler.PlatformScheduler$PlatformSchedulerService"
           android:permission="android.permission.BIND_JOB_SERVICE"
           android:exported="true"/>

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `PlatformScheduler.PlatformSchedulerService` | A `JobService` that starts the target service if the requirements are met.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `PlatformScheduler​(Context context, int jobId)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `cancel()` | Cancels anything that was previously scheduled, or else does nothing.
    `Requirements` | `getSupportedRequirements​(Requirements requirements)` | Checks whether this `Scheduler` supports the provided `Requirements`.
    `boolean` | `schedule​(Requirements requirements, String servicePackage, String serviceAction)` | Schedules a service to be started in the foreground when some `Requirements` are met.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PlatformScheduler

          @RequiresPermission("android.permission.RECEIVE_BOOT_COMPLETED")
          public PlatformScheduler​(Context context,
                                   int jobId)

      Parameters:
        `context` - Any context.
        `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 `schedule(Requirements, String, String)` or `cancel()` are called.

  - ### Method Detail

    - #### schedule

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

      Description copied from interface: `Scheduler`
      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 `Service.startForeground(int, Notification)` to make itself a foreground service, as documented by `ContextWrapper.startForegroundService(Intent)`.

      Specified by:
        `schedule` in interface `Scheduler`
      Parameters:
        `requirements` - The requirements.
        `servicePackage` - The package name.
        `serviceAction` - The action with which the service will be started.
      Returns:
        Whether scheduling was successful.

    - #### cancel

          public boolean cancel()

      Description copied from interface: `Scheduler`
      Cancels anything that was previously scheduled, or else does nothing.
      Specified by:
        `cancel` in interface `Scheduler`
      Returns:
        Whether cancellation was successful.

    - #### getSupportedRequirements

          public Requirements getSupportedRequirements​(Requirements requirements)

      Description copied from interface: `Scheduler`
      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.
      Specified by:
        `getSupportedRequirements` in interface `Scheduler`
      Parameters:
        `requirements` - The requirements to check.
      Returns:
        The supported requirements.