Package com.google.android.exoplayer2.offline

## Class DownloadService

- java.lang.Object
- - android.content.Context
  - - android.content.ContextWrapper
    - - android.app.Service
      - - com.google.android.exoplayer2.offline.DownloadService

- All Implemented Interfaces:
    `ComponentCallbacks`, `ComponentCallbacks2`

      public abstract class DownloadService
      extends Service

  A `Service` for downloading media.

  Apps with target SDK 33 and greater need to add the `android.permission.POST_NOTIFICATIONS` permission to the manifest and request the permission at runtime before starting downloads. Without that permission granted by the user, notifications posted by this service are not displayed. See the official UI guide for more detailed information.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static String` | `ACTION_ADD_DOWNLOAD` | Adds a new download.
    `static String` | `ACTION_INIT` | Starts a download service to resume any ongoing downloads.
    `static String` | `ACTION_PAUSE_DOWNLOADS` | Pauses all downloads.
    `static String` | `ACTION_REMOVE_ALL_DOWNLOADS` | Removes all downloads.
    `static String` | `ACTION_REMOVE_DOWNLOAD` | Removes a download.
    `static String` | `ACTION_RESUME_DOWNLOADS` | Resumes all downloads except those that have a non-zero `Download.stopReason`.
    `static String` | `ACTION_SET_REQUIREMENTS` | Sets the requirements that need to be met for downloads to progress.
    `static String` | `ACTION_SET_STOP_REASON` | Sets the stop reason for one or all downloads.
    `static long` | `DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL` | Default foreground notification update interval in milliseconds.
    `static int` | `FOREGROUND_NOTIFICATION_ID_NONE` | Invalid foreground notification id that can be used to run the service in the background.
    `static String` | `KEY_CONTENT_ID` | Key for the `String` content id in `ACTION_SET_STOP_REASON` and `ACTION_REMOVE_DOWNLOAD` intents.
    `static String` | `KEY_DOWNLOAD_REQUEST` | Key for the `DownloadRequest` in `ACTION_ADD_DOWNLOAD` intents.
    `static String` | `KEY_FOREGROUND` | Key for a boolean extra that can be set on any intent to indicate whether the service was started in the foreground.
    `static String` | `KEY_REQUIREMENTS` | Key for the `Requirements` in `ACTION_SET_REQUIREMENTS` intents.
    `static String` | `KEY_STOP_REASON` | Key for the integer stop reason in `ACTION_SET_STOP_REASON` and `ACTION_ADD_DOWNLOAD` intents.

    - ### Fields inherited from class android.app.Service

      `START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_LEGACY, STOP_FOREGROUND_REMOVE`

    - ### Fields inherited from class android.content.Context

      `ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APP_SEARCH_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_IMPORTANT, BIND_INCLUDE_CAPABILITIES, BIND_NOT_FOREGROUND, BIND_NOT_PERCEPTIBLE, BIND_WAIVE_PRIORITY, BIOMETRIC_SERVICE, BLOB_STORE_SERVICE, BLUETOOTH_SERVICE, BUGREPORT_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_DIAGNOSTICS_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, CROSS_PROFILE_APPS_SERVICE, DEVICE_POLICY_SERVICE, DISPLAY_HASH_SERVICE, DISPLAY_SERVICE, DOMAIN_VERIFICATION_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, EUICC_SERVICE, FILE_INTEGRITY_SERVICE, FINGERPRINT_SERVICE, GAME_SERVICE, HARDWARE_PROPERTIES_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, IPSEC_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCALE_SERVICE, LOCATION_SERVICE, MEDIA_COMMUNICATION_SERVICE, MEDIA_METRICS_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, PEOPLE_SERVICE, PERFORMANCE_HINT_SERVICE, POWER_SERVICE, PRINT_SERVICE, RECEIVER_EXPORTED, RECEIVER_NOT_EXPORTED, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, ROLE_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_IMS_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, TV_INTERACTIVE_APP_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_MANAGER_SERVICE, VIBRATOR_SERVICE, VPN_MANAGEMENT_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_RANGING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE`

    - ### Fields inherited from interface android.content.ComponentCallbacks2

      `TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `DownloadService​(int foregroundNotificationId)` | Creates a DownloadService.
    `protected` | `DownloadService​(int foregroundNotificationId, long foregroundNotificationUpdateInterval)` | Creates a DownloadService.
    `protected` | `DownloadService​(int foregroundNotificationId, long foregroundNotificationUpdateInterval, String channelId, int channelNameResourceId)` | Deprecated. Use `DownloadService(int, long, String, int, int)`.
    `protected` | `DownloadService​(int foregroundNotificationId, long foregroundNotificationUpdateInterval, String channelId, int channelNameResourceId, int channelDescriptionResourceId)` | Creates a DownloadService.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static Intent` | `buildAddDownloadIntent​(Context context, Class<? extends DownloadService> clazz, DownloadRequest downloadRequest, boolean foreground)` | Builds an `Intent` for adding a new download.
    `static Intent` | `buildAddDownloadIntent​(Context context, Class<? extends DownloadService> clazz, DownloadRequest downloadRequest, int stopReason, boolean foreground)` | Builds an `Intent` for adding a new download.
    `static Intent` | `buildPauseDownloadsIntent​(Context context, Class<? extends DownloadService> clazz, boolean foreground)` | Builds an `Intent` to pause all downloads.
    `static Intent` | `buildRemoveAllDownloadsIntent​(Context context, Class<? extends DownloadService> clazz, boolean foreground)` | Builds an `Intent` for removing all downloads.
    `static Intent` | `buildRemoveDownloadIntent​(Context context, Class<? extends DownloadService> clazz, String id, boolean foreground)` | Builds an `Intent` for removing the download with the `id`.
    `static Intent` | `buildResumeDownloadsIntent​(Context context, Class<? extends DownloadService> clazz, boolean foreground)` | Builds an `Intent` for resuming all downloads.
    `static Intent` | `buildSetRequirementsIntent​(Context context, Class<? extends DownloadService> clazz, Requirements requirements, boolean foreground)` | Builds an `Intent` for setting the requirements that need to be met for downloads to progress.
    `static Intent` | `buildSetStopReasonIntent​(Context context, Class<? extends DownloadService> clazz, String id, int stopReason, boolean foreground)` | Builds an `Intent` for setting the stop reason for one or all downloads.
    `static void` | `clearDownloadManagerHelpers()` | Clear all download manager helpers before restarting the service.
    `protected abstract DownloadManager` | `getDownloadManager()` | Returns a `DownloadManager` to be used to downloaded content.
    `protected abstract Notification` | `getForegroundNotification​(List<Download> downloads, @com.google.android.exoplayer2.scheduler.Requirements.RequirementFlags int notMetRequirements)` | Returns a notification to be displayed when this service running in the foreground.
    `protected abstract Scheduler` | `getScheduler()` | Returns a `Scheduler` to restart the service when requirements for downloads to continue are met.
    `protected void` | `invalidateForegroundNotification()` | Invalidates the current foreground notification and causes `getForegroundNotification(List, int)` to be invoked again if the service isn't stopped.
    `IBinder` | `onBind​(Intent intent)` | Throws `UnsupportedOperationException` because this service is not designed to be bound.
    `void` | `onCreate()` |
    `void` | `onDestroy()` |
    `int` | `onStartCommand​(Intent intent, int flags, int startId)` |
    `void` | `onTaskRemoved​(Intent rootIntent)` |
    `static void` | `sendAddDownload​(Context context, Class<? extends DownloadService> clazz, DownloadRequest downloadRequest, boolean foreground)` | Starts the service if not started already and adds a new download.
    `static void` | `sendAddDownload​(Context context, Class<? extends DownloadService> clazz, DownloadRequest downloadRequest, int stopReason, boolean foreground)` | Starts the service if not started already and adds a new download.
    `static void` | `sendPauseDownloads​(Context context, Class<? extends DownloadService> clazz, boolean foreground)` | Starts the service if not started already and pauses all downloads.
    `static void` | `sendRemoveAllDownloads​(Context context, Class<? extends DownloadService> clazz, boolean foreground)` | Starts the service if not started already and removes all downloads.
    `static void` | `sendRemoveDownload​(Context context, Class<? extends DownloadService> clazz, String id, boolean foreground)` | Starts the service if not started already and removes a download.
    `static void` | `sendResumeDownloads​(Context context, Class<? extends DownloadService> clazz, boolean foreground)` | Starts the service if not started already and resumes all downloads.
    `static void` | `sendSetRequirements​(Context context, Class<? extends DownloadService> clazz, Requirements requirements, boolean foreground)` | Starts the service if not started already and sets the requirements that need to be met for downloads to progress.
    `static void` | `sendSetStopReason​(Context context, Class<? extends DownloadService> clazz, String id, int stopReason, boolean foreground)` | Starts the service if not started already and sets the stop reason for one or all downloads.
    `static void` | `start​(Context context, Class<? extends DownloadService> clazz)` | Starts a download service to resume any ongoing downloads.
    `static void` | `startForeground​(Context context, Class<? extends DownloadService> clazz)` | Starts the service in the foreground without adding a new download request.

    - ### Methods inherited from class android.app.Service

      `attachBaseContext, dump, getApplication, getForegroundServiceType, onConfigurationChanged, onLowMemory, onRebind, onStart, onTrimMemory, onUnbind, startForeground, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult`

    - ### Methods inherited from class android.content.ContextWrapper

      `bindIsolatedService, bindService, bindService, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingOrSelfUriPermissions, checkCallingPermission, checkCallingUriPermission, checkCallingUriPermissions, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermissions, clearWallpaper, createAttributionContext, createConfigurationContext, createContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getAttributionSource, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getParams, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, isUiContext, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerComponentCallbacks, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeSelfPermissionsOnKill, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startForegroundService, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterComponentCallbacks, unregisterReceiver, updateServiceGroup`

    - ### Methods inherited from class android.content.Context

      `getColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, revokeSelfPermissionOnKill, sendBroadcastWithMultiplePermissions`

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

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

- - ### Field Detail

    - #### ACTION_INIT

          public static final String ACTION_INIT

      Starts a download service to resume any ongoing downloads. Extras:
      - `KEY_FOREGROUND` - See `KEY_FOREGROUND`.
      See Also:
        Constant Field Values

    - #### ACTION_ADD_DOWNLOAD

          public static final String ACTION_ADD_DOWNLOAD

      Adds a new download. Extras:
      - `KEY_DOWNLOAD_REQUEST` - A `DownloadRequest` defining the download to be added.
      - `KEY_STOP_REASON` - An initial stop reason for the download. If omitted `Download.STOP_REASON_NONE` is used.
      - `KEY_FOREGROUND` - See `KEY_FOREGROUND`.
      See Also:
        Constant Field Values

    - #### ACTION_REMOVE_DOWNLOAD

          public static final String ACTION_REMOVE_DOWNLOAD

      Removes a download. Extras:
      - `KEY_CONTENT_ID` - The content id of a download to remove.
      - `KEY_FOREGROUND` - See `KEY_FOREGROUND`.
      See Also:
        Constant Field Values

    - #### ACTION_REMOVE_ALL_DOWNLOADS

          public static final String ACTION_REMOVE_ALL_DOWNLOADS

      Removes all downloads. Extras:
      - `KEY_FOREGROUND` - See `KEY_FOREGROUND`.
      See Also:
        Constant Field Values

    - #### ACTION_RESUME_DOWNLOADS

          public static final String ACTION_RESUME_DOWNLOADS

      Resumes all downloads except those that have a non-zero `Download.stopReason`. Extras:
      - `KEY_FOREGROUND` - See `KEY_FOREGROUND`.
      See Also:
        Constant Field Values

    - #### ACTION_PAUSE_DOWNLOADS

          public static final String ACTION_PAUSE_DOWNLOADS

      Pauses all downloads. Extras:
      - `KEY_FOREGROUND` - See `KEY_FOREGROUND`.
      See Also:
        Constant Field Values

    - #### ACTION_SET_STOP_REASON

          public static final String ACTION_SET_STOP_REASON

      Sets the stop reason for one or all downloads. To clear the stop reason, pass `Download.STOP_REASON_NONE`. Extras:
      - `KEY_CONTENT_ID` - The content id of a single download to update with the stop reason. If omitted, all downloads will be updated.
      - `KEY_STOP_REASON` - An application provided reason for stopping the download or downloads, or `Download.STOP_REASON_NONE` to clear the stop reason.
      - `KEY_FOREGROUND` - See `KEY_FOREGROUND`.
      See Also:
        Constant Field Values

    - #### ACTION_SET_REQUIREMENTS

          public static final String ACTION_SET_REQUIREMENTS

      Sets the requirements that need to be met for downloads to progress. Extras:
      - `KEY_REQUIREMENTS` - A `Requirements`.
      - `KEY_FOREGROUND` - See `KEY_FOREGROUND`.
      See Also:
        Constant Field Values

    - #### KEY_DOWNLOAD_REQUEST

          public static final String KEY_DOWNLOAD_REQUEST

      Key for the `DownloadRequest` in `ACTION_ADD_DOWNLOAD` intents.
      See Also:
        Constant Field Values

    - #### KEY_CONTENT_ID

          public static final String KEY_CONTENT_ID

      Key for the `String` content id in `ACTION_SET_STOP_REASON` and `ACTION_REMOVE_DOWNLOAD` intents.
      See Also:
        Constant Field Values

    - #### KEY_STOP_REASON

          public static final String KEY_STOP_REASON

      Key for the integer stop reason in `ACTION_SET_STOP_REASON` and `ACTION_ADD_DOWNLOAD` intents.
      See Also:
        Constant Field Values

    - #### KEY_REQUIREMENTS

          public static final String KEY_REQUIREMENTS

      Key for the `Requirements` in `ACTION_SET_REQUIREMENTS` intents.
      See Also:
        Constant Field Values

    - #### KEY_FOREGROUND

          public static final String KEY_FOREGROUND

      Key for a boolean extra that can be set on any intent to indicate whether the service was started in the foreground. If set, the service is guaranteed to call `Service.startForeground(int, Notification)`.
      See Also:
        Constant Field Values

    - #### FOREGROUND_NOTIFICATION_ID_NONE

          public static final int FOREGROUND_NOTIFICATION_ID_NONE

      Invalid foreground notification id that can be used to run the service in the background.
      See Also:
        Constant Field Values

    - #### DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL

          public static final long DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL

      Default foreground notification update interval in milliseconds.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DownloadService

          protected DownloadService​(int foregroundNotificationId)

      Creates a DownloadService.

      If `foregroundNotificationId` is `FOREGROUND_NOTIFICATION_ID_NONE` then the service will only ever run in the background, and no foreground notification will be displayed.

      If `foregroundNotificationId` is not `FOREGROUND_NOTIFICATION_ID_NONE` then the service will run in the foreground. The foreground notification will be updated at least as often as the interval specified by `DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL`.

      Parameters:
        `foregroundNotificationId` - The notification id for the foreground notification, or `FOREGROUND_NOTIFICATION_ID_NONE` if the service should only ever run in the background.

    - #### DownloadService

          protected DownloadService​(int foregroundNotificationId,
                                    long foregroundNotificationUpdateInterval)

      Creates a DownloadService.
      Parameters:
        `foregroundNotificationId` - The notification id for the foreground notification, or `FOREGROUND_NOTIFICATION_ID_NONE` if the service should only ever run in the background.
        `foregroundNotificationUpdateInterval` - The maximum interval between updates to the foreground notification, in milliseconds. Ignored if `foregroundNotificationId` is `FOREGROUND_NOTIFICATION_ID_NONE`.

    - #### DownloadService

          @Deprecated
          protected DownloadService​(int foregroundNotificationId,
                                    long foregroundNotificationUpdateInterval,
                                    @Nullable
                                    String channelId,
                                    @StringRes
                                    int channelNameResourceId)

      Deprecated.
      Use `DownloadService(int, long, String, int, int)`.

    - #### DownloadService

          protected DownloadService​(int foregroundNotificationId,
                                    long foregroundNotificationUpdateInterval,
                                    @Nullable
                                    String channelId,
                                    @StringRes
                                    int channelNameResourceId,
                                    @StringRes
                                    int channelDescriptionResourceId)

      Creates a DownloadService.
      Parameters:
        `foregroundNotificationId` - The notification id for the foreground notification, or `FOREGROUND_NOTIFICATION_ID_NONE` if the service should only ever run in the background.
        `foregroundNotificationUpdateInterval` - The maximum interval between updates to the foreground notification, in milliseconds. Ignored if `foregroundNotificationId` is `FOREGROUND_NOTIFICATION_ID_NONE`.
        `channelId` - An id for a low priority notification channel to create, or `null` if the app will take care of creating a notification channel if needed. If specified, must be unique per package. The value may be truncated if it's too long. Ignored if `foregroundNotificationId` is `FOREGROUND_NOTIFICATION_ID_NONE`.
        `channelNameResourceId` - A string resource identifier for the user visible name of the notification channel. The recommended maximum length is 40 characters. The value may be truncated if it's too long. Ignored if `channelId` is null or if `foregroundNotificationId` is `FOREGROUND_NOTIFICATION_ID_NONE`.
        `channelDescriptionResourceId` - A string resource identifier for the user visible description of the notification channel, or 0 if no description is provided. The recommended maximum length is 300 characters. The value may be truncated if it is too long. Ignored if `channelId` is null or if `foregroundNotificationId` is `FOREGROUND_NOTIFICATION_ID_NONE`.

  - ### Method Detail

    - #### buildAddDownloadIntent

          public static Intent buildAddDownloadIntent​(Context context,
                                                      Class<? extends DownloadService> clazz,
                                                      DownloadRequest downloadRequest,
                                                      boolean foreground)

      Builds an `Intent` for adding a new download.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service being targeted by the intent.
        `downloadRequest` - The request to be executed.
        `foreground` - Whether this intent will be used to start the service in the foreground.
      Returns:
        The created intent.

    - #### buildAddDownloadIntent

          public static Intent buildAddDownloadIntent​(Context context,
                                                      Class<? extends DownloadService> clazz,
                                                      DownloadRequest downloadRequest,
                                                      int stopReason,
                                                      boolean foreground)

      Builds an `Intent` for adding a new download.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service being targeted by the intent.
        `downloadRequest` - The request to be executed.
        `stopReason` - An initial stop reason for the download, or `Download.STOP_REASON_NONE` if the download should be started.
        `foreground` - Whether this intent will be used to start the service in the foreground.
      Returns:
        The created intent.

    - #### buildRemoveDownloadIntent

          public static Intent buildRemoveDownloadIntent​(Context context,
                                                         Class<? extends DownloadService> clazz,
                                                         String id,
                                                         boolean foreground)

      Builds an `Intent` for removing the download with the `id`.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service being targeted by the intent.
        `id` - The content id.
        `foreground` - Whether this intent will be used to start the service in the foreground.
      Returns:
        The created intent.

    - #### buildRemoveAllDownloadsIntent

          public static Intent buildRemoveAllDownloadsIntent​(Context context,
                                                             Class<? extends DownloadService> clazz,
                                                             boolean foreground)

      Builds an `Intent` for removing all downloads.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service being targeted by the intent.
        `foreground` - Whether this intent will be used to start the service in the foreground.
      Returns:
        The created intent.

    - #### buildResumeDownloadsIntent

          public static Intent buildResumeDownloadsIntent​(Context context,
                                                          Class<? extends DownloadService> clazz,
                                                          boolean foreground)

      Builds an `Intent` for resuming all downloads.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service being targeted by the intent.
        `foreground` - Whether this intent will be used to start the service in the foreground.
      Returns:
        The created intent.

    - #### buildPauseDownloadsIntent

          public static Intent buildPauseDownloadsIntent​(Context context,
                                                         Class<? extends DownloadService> clazz,
                                                         boolean foreground)

      Builds an `Intent` to pause all downloads.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service being targeted by the intent.
        `foreground` - Whether this intent will be used to start the service in the foreground.
      Returns:
        The created intent.

    - #### buildSetStopReasonIntent

          public static Intent buildSetStopReasonIntent​(Context context,
                                                        Class<? extends DownloadService> clazz,
                                                        @Nullable
                                                        String id,
                                                        int stopReason,
                                                        boolean foreground)

      Builds an `Intent` for setting the stop reason for one or all downloads. To clear the stop reason, pass `Download.STOP_REASON_NONE`.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service being targeted by the intent.
        `id` - The content id, or `null` to set the stop reason for all downloads.
        `stopReason` - An application defined stop reason.
        `foreground` - Whether this intent will be used to start the service in the foreground.
      Returns:
        The created intent.

    - #### buildSetRequirementsIntent

          public static Intent buildSetRequirementsIntent​(Context context,
                                                          Class<? extends DownloadService> clazz,
                                                          Requirements requirements,
                                                          boolean foreground)

      Builds an `Intent` for setting the requirements that need to be met for downloads to progress.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service being targeted by the intent.
        `requirements` - A `Requirements`.
        `foreground` - Whether this intent will be used to start the service in the foreground.
      Returns:
        The created intent.

    - #### sendAddDownload

          public static void sendAddDownload​(Context context,
                                             Class<? extends DownloadService> clazz,
                                             DownloadRequest downloadRequest,
                                             boolean foreground)

      Starts the service if not started already and adds a new download.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
        `downloadRequest` - The request to be executed.
        `foreground` - Whether the service is started in the foreground.

    - #### sendAddDownload

          public static void sendAddDownload​(Context context,
                                             Class<? extends DownloadService> clazz,
                                             DownloadRequest downloadRequest,
                                             int stopReason,
                                             boolean foreground)

      Starts the service if not started already and adds a new download.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
        `downloadRequest` - The request to be executed.
        `stopReason` - An initial stop reason for the download, or `Download.STOP_REASON_NONE` if the download should be started.
        `foreground` - Whether the service is started in the foreground.

    - #### sendRemoveDownload

          public static void sendRemoveDownload​(Context context,
                                                Class<? extends DownloadService> clazz,
                                                String id,
                                                boolean foreground)

      Starts the service if not started already and removes a download.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
        `id` - The content id.
        `foreground` - Whether the service is started in the foreground.

    - #### sendRemoveAllDownloads

          public static void sendRemoveAllDownloads​(Context context,
                                                    Class<? extends DownloadService> clazz,
                                                    boolean foreground)

      Starts the service if not started already and removes all downloads.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
        `foreground` - Whether the service is started in the foreground.

    - #### sendResumeDownloads

          public static void sendResumeDownloads​(Context context,
                                                 Class<? extends DownloadService> clazz,
                                                 boolean foreground)

      Starts the service if not started already and resumes all downloads.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
        `foreground` - Whether the service is started in the foreground.

    - #### sendPauseDownloads

          public static void sendPauseDownloads​(Context context,
                                                Class<? extends DownloadService> clazz,
                                                boolean foreground)

      Starts the service if not started already and pauses all downloads.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
        `foreground` - Whether the service is started in the foreground.

    - #### sendSetStopReason

          public static void sendSetStopReason​(Context context,
                                               Class<? extends DownloadService> clazz,
                                               @Nullable
                                               String id,
                                               int stopReason,
                                               boolean foreground)

      Starts the service if not started already and sets the stop reason for one or all downloads. To clear stop reason, pass `Download.STOP_REASON_NONE`.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
        `id` - The content id, or `null` to set the stop reason for all downloads.
        `stopReason` - An application defined stop reason.
        `foreground` - Whether the service is started in the foreground.

    - #### sendSetRequirements

          public static void sendSetRequirements​(Context context,
                                                 Class<? extends DownloadService> clazz,
                                                 Requirements requirements,
                                                 boolean foreground)

      Starts the service if not started already and sets the requirements that need to be met for downloads to progress.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
        `requirements` - A `Requirements`.
        `foreground` - Whether the service is started in the foreground.

    - #### start

          public static void start​(Context context,
                                   Class<? extends DownloadService> clazz)

      Starts a download service to resume any ongoing downloads.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
      See Also:
        `startForeground(Context, Class)`

    - #### startForeground

          public static void startForeground​(Context context,
                                             Class<? extends DownloadService> clazz)

      Starts the service in the foreground without adding a new download request. If there are any not finished downloads and the requirements are met, the service resumes downloading. Otherwise it stops immediately.
      Parameters:
        `context` - A `Context`.
        `clazz` - The concrete download service to be started.
      See Also:
        `start(Context, Class)`

    - #### clearDownloadManagerHelpers

          public static void clearDownloadManagerHelpers()

      Clear all download manager helpers before restarting the service.

      Calling this method is normally only required if an app supports downloading content for multiple users for which different download directories should be used.

    - #### onCreate

          public void onCreate()

      Overrides:
        `onCreate` in class `Service`

    - #### onStartCommand

          public int onStartCommand​(@Nullable
                                    Intent intent,
                                    int flags,
                                    int startId)

      Overrides:
        `onStartCommand` in class `Service`

    - #### onTaskRemoved

          public void onTaskRemoved​(Intent rootIntent)

      Overrides:
        `onTaskRemoved` in class `Service`

    - #### onDestroy

          public void onDestroy()

      Overrides:
        `onDestroy` in class `Service`

    - #### onBind

          @Nullable
          public final IBinder onBind​(Intent intent)

      Throws `UnsupportedOperationException` because this service is not designed to be bound.
      Specified by:
        `onBind` in class `Service`

    - #### getDownloadManager

          protected abstract DownloadManager getDownloadManager()

      Returns a `DownloadManager` to be used to downloaded content. For each concrete download service subclass, this is called once in the lifecycle of the process when `onCreate()` is called on the first instance of the service. If the service is destroyed and a new instance is created later, the new instance will use the previously returned `DownloadManager` without this method being called again.

    - #### getScheduler

          @Nullable
          protected abstract Scheduler getScheduler()

      Returns a `Scheduler` to restart the service when requirements for downloads to continue are met.

      This method is not called on all devices or for all service configurations. When it is called, it's called only once in the life cycle of the process. If a service has unfinished downloads that cannot make progress due to unmet requirements, it will behave according to the first matching case below:

      - If the service has `foregroundNotificationId` set to `FOREGROUND_NOTIFICATION_ID_NONE`, then this method will not be called. The service will remain in the background until the downloads are able to continue to completion or the service is killed by the platform.
      - If the device API level is less than 31, a `Scheduler` is returned from this method, and the returned `Scheduler` `supports` all of the requirements that have been specified for downloads to continue, then the service will stop itself and the `Scheduler` will be used to restart it in the foreground when the requirements are met.
      - If the device API level is less than 31 and either `null` or a `Scheduler` that does not `support` all of the requirements is returned from this method, then the service will remain in the foreground until the downloads are able to continue to completion.
      - If the device API level is 31 or above, then this method will not be called and the service will remain in the foreground until the downloads are able to continue to completion. A `Scheduler` cannot be used for this case due to Android 12 foreground service launch restrictions.

    - #### getForegroundNotification

          protected abstract Notification getForegroundNotification​(List<Download> downloads,
                                                                    @RequirementFlags
                                                                    @com.google.android.exoplayer2.scheduler.Requirements.RequirementFlags int notMetRequirements)

      Returns a notification to be displayed when this service running in the foreground.

      Download services that do not wish to run in the foreground should be created by setting the `foregroundNotificationId` constructor argument to `FOREGROUND_NOTIFICATION_ID_NONE`. This method is not called for such services, meaning it can be implemented to throw `UnsupportedOperationException`.

      Parameters:
        `downloads` - The current downloads.
        `notMetRequirements` - Any requirements for downloads that are not currently met.
      Returns:
        The foreground notification to display.

    - #### invalidateForegroundNotification

          protected final void invalidateForegroundNotification()

      Invalidates the current foreground notification and causes `getForegroundNotification(List, int)` to be invoked again if the service isn't stopped.