DownloadService
@UnstableApi
abstract class DownloadService : Service
| kotlin.Any | ||||
| ↳ | android.content.Context | |||
| ↳ | android.content.ContextWrapper | |||
| ↳ | android.app.Service | |||
| ↳ | androidx.media3.exoplayer.offline.DownloadService |
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.
Summary
Constants |
|
|---|---|
const String! |
ACTION_ADD_DOWNLOAD = "androidx.media3.exoplayer.downloadService.action.ADD_DOWNLOAD"Adds a new download. |
const String! |
ACTION_INIT = "androidx.media3.exoplayer.downloadService.action.INIT"Starts a download service to resume any ongoing downloads. |
const String! |
ACTION_PAUSE_DOWNLOADS = "androidx.media3.exoplayer.downloadService.action.PAUSE_DOWNLOADS"Pauses all downloads. |
const String! |
ACTION_REMOVE_ALL_DOWNLOADS = "androidx.media3.exoplayer.downloadService.action.REMOVE_ALL_DOWNLOADS"Removes all downloads. |
const String! |
ACTION_REMOVE_DOWNLOAD = "androidx.media3.exoplayer.downloadService.action.REMOVE_DOWNLOAD"Removes a download. |
const String! |
ACTION_RESUME_DOWNLOADS = "androidx.media3.exoplayer.downloadService.action.RESUME_DOWNLOADS"Resumes all downloads except those that have a non-zero |
const String! |
ACTION_SET_REQUIREMENTS = "androidx.media3.exoplayer.downloadService.action.SET_REQUIREMENTS"Sets the requirements that need to be met for downloads to progress. |
const String! |
ACTION_SET_STOP_REASON = "androidx.media3.exoplayer.downloadService.action.SET_STOP_REASON"Sets the stop reason for one or all downloads. |
const Long |
Default foreground notification update interval in milliseconds. |
const Int |
Invalid foreground notification id that can be used to run the service in the background. |
const String! |
KEY_CONTENT_ID = "content_id"Key for the |
const String! |
KEY_DOWNLOAD_REQUEST = "download_request"Key for the |
const String! |
KEY_FOREGROUND = "foreground"Key for a boolean extra that can be set on any intent to indicate whether the service was started in the foreground. |
const String! |
KEY_REQUIREMENTS = "requirements"Key for the |
const String! |
KEY_STOP_REASON = "stop_reason"Key for the integer stop reason in |
Protected constructors |
|---|
DownloadService(foregroundNotificationId: Int)Creates a DownloadService. |
DownloadService(Creates a DownloadService. |
DownloadService(Creates a DownloadService. |
Public functions |
|
|---|---|
java-static Intent! |
buildAddDownloadIntent(Builds an |
java-static Intent! |
buildAddDownloadIntent(Builds an |
java-static Intent! |
buildPauseDownloadsIntent(Builds an |
java-static Intent! |
buildRemoveAllDownloadsIntent(Builds an |
java-static Intent! |
buildRemoveDownloadIntent(Builds an |
java-static Intent! |
buildResumeDownloadsIntent(Builds an |
java-static Intent! |
buildSetRequirementsIntent(Builds an |
java-static Intent! |
buildSetStopReasonIntent(Builds an |
java-static Unit |
Clear all |
IBinder? |
Throws |
Unit |
onCreate() |
Unit |
|
Int |
onStartCommand(intent: Intent?, flags: Int, startId: Int) |
Unit |
onTaskRemoved(rootIntent: Intent!) |
Unit |
|
java-static Unit |
sendAddDownload(Starts the service if not started already and adds a new download. |
java-static Unit |
sendAddDownload(Starts the service if not started already and adds a new download. |
java-static Unit |
sendPauseDownloads(Starts the service if not started already and pauses all downloads. |
java-static Unit |
sendRemoveAllDownloads(Starts the service if not started already and removes all downloads. |
java-static Unit |
sendRemoveDownload(Starts the service if not started already and removes a download. |
java-static Unit |
sendResumeDownloads(Starts the service if not started already and resumes all downloads. |
java-static Unit |
sendSetRequirements(Starts the service if not started already and sets the requirements that need to be met for downloads to progress. |
java-static Unit |
sendSetStopReason(Starts the service if not started already and sets the stop reason for one or all downloads. |
java-static Unit |
start(context: Context!, clazz: Class<DownloadService!>!)Starts a download service to resume any ongoing downloads. |
java-static Unit |
startForeground(context: Context!, clazz: Class<DownloadService!>!)Starts the service in the foreground without adding a new download request. |
Protected functions |
|
|---|---|
abstract DownloadManager! |
Returns a |
abstract Notification! |
getForegroundNotification(Returns a notification to be displayed when this service running in the foreground. |
abstract Scheduler? |
Returns a |
Unit |
Invalidates the current foreground notification and causes |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
ACTION_ADD_DOWNLOAD
const val ACTION_ADD_DOWNLOAD = "androidx.media3.exoplayer.downloadService.action.ADD_DOWNLOAD": String!
Adds a new download. Extras:
KEY_DOWNLOAD_REQUEST- ADownloadRequestdefining the download to be added.KEY_STOP_REASON- An initial stop reason for the download. If omittedSTOP_REASON_NONEis used.KEY_FOREGROUND- SeeKEY_FOREGROUND.
ACTION_INIT
const val ACTION_INIT = "androidx.media3.exoplayer.downloadService.action.INIT": String!
Starts a download service to resume any ongoing downloads. Extras:
KEY_FOREGROUND- SeeKEY_FOREGROUND.
ACTION_PAUSE_DOWNLOADS
const val ACTION_PAUSE_DOWNLOADS = "androidx.media3.exoplayer.downloadService.action.PAUSE_DOWNLOADS": String!
Pauses all downloads. Extras:
KEY_FOREGROUND- SeeKEY_FOREGROUND.
ACTION_REMOVE_ALL_DOWNLOADS
const val ACTION_REMOVE_ALL_DOWNLOADS = "androidx.media3.exoplayer.downloadService.action.REMOVE_ALL_DOWNLOADS": String!
Removes all downloads. Extras:
KEY_FOREGROUND- SeeKEY_FOREGROUND.
ACTION_REMOVE_DOWNLOAD
const val ACTION_REMOVE_DOWNLOAD = "androidx.media3.exoplayer.downloadService.action.REMOVE_DOWNLOAD": String!
Removes a download. Extras:
KEY_CONTENT_ID- The content id of a download to remove.KEY_FOREGROUND- SeeKEY_FOREGROUND.
ACTION_RESUME_DOWNLOADS
const val ACTION_RESUME_DOWNLOADS = "androidx.media3.exoplayer.downloadService.action.RESUME_DOWNLOADS": String!
Resumes all downloads except those that have a non-zero stopReason. Extras:
KEY_FOREGROUND- SeeKEY_FOREGROUND.
ACTION_SET_REQUIREMENTS
const val ACTION_SET_REQUIREMENTS = "androidx.media3.exoplayer.downloadService.action.SET_REQUIREMENTS": String!
Sets the requirements that need to be met for downloads to progress. Extras:
KEY_REQUIREMENTS- ARequirements.KEY_FOREGROUND- SeeKEY_FOREGROUND.
ACTION_SET_STOP_REASON
const val ACTION_SET_STOP_REASON = "androidx.media3.exoplayer.downloadService.action.SET_STOP_REASON": String!
Sets the stop reason for one or all downloads. To clear the stop reason, pass 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, orSTOP_REASON_NONEto clear the stop reason.KEY_FOREGROUND- SeeKEY_FOREGROUND.
DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL
const val DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL = 1000: Long
Default foreground notification update interval in milliseconds.
FOREGROUND_NOTIFICATION_ID_NONE
const val FOREGROUND_NOTIFICATION_ID_NONE = 0: Int
Invalid foreground notification id that can be used to run the service in the background.
KEY_CONTENT_ID
const val KEY_CONTENT_ID = "content_id": String!
Key for the String content id in ACTION_SET_STOP_REASON and ACTION_REMOVE_DOWNLOAD intents.
KEY_DOWNLOAD_REQUEST
const val KEY_DOWNLOAD_REQUEST = "download_request": String!
Key for the DownloadRequest in ACTION_ADD_DOWNLOAD intents.
KEY_FOREGROUND
const val KEY_FOREGROUND = "foreground": String!
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 startForeground.
KEY_REQUIREMENTS
const val KEY_REQUIREMENTS = "requirements": String!
Key for the Requirements in ACTION_SET_REQUIREMENTS intents.
KEY_STOP_REASON
const val KEY_STOP_REASON = "stop_reason": String!
Key for the integer stop reason in ACTION_SET_STOP_REASON and ACTION_ADD_DOWNLOAD intents.
Protected constructors
DownloadService
protected DownloadService(foregroundNotificationId: Int)
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: Int |
The notification id for the foreground notification, or |
DownloadService
protected DownloadService(
foregroundNotificationId: Int,
foregroundNotificationUpdateInterval: Long
)
Creates a DownloadService.
| Parameters | |
|---|---|
foregroundNotificationId: Int |
The notification id for the foreground notification, or |
foregroundNotificationUpdateInterval: Long |
The maximum interval between updates to the foreground notification, in milliseconds. Ignored if |
DownloadService
protected DownloadService(
foregroundNotificationId: Int,
foregroundNotificationUpdateInterval: Long,
channelId: String?,
channelNameResourceId: @StringRes Int,
channelDescriptionResourceId: @StringRes Int
)
Creates a DownloadService.
| Parameters | |
|---|---|
foregroundNotificationId: Int |
The notification id for the foreground notification, or |
foregroundNotificationUpdateInterval: Long |
The maximum interval between updates to the foreground notification, in milliseconds. Ignored if |
channelId: String? |
An id for a low priority notification channel to create, or |
channelNameResourceId: @StringRes Int |
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 |
channelDescriptionResourceId: @StringRes Int |
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 |
Public functions
buildAddDownloadIntent
java-static fun buildAddDownloadIntent(
context: Context!,
clazz: Class<DownloadService!>!,
downloadRequest: DownloadRequest!,
foreground: Boolean
): Intent!
Builds an Intent for adding a new download.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service being targeted by the intent. |
downloadRequest: DownloadRequest! |
The request to be executed. |
foreground: Boolean |
Whether this intent will be used to start the service in the foreground. |
| Returns | |
|---|---|
Intent! |
The created intent. |
buildAddDownloadIntent
java-static fun buildAddDownloadIntent(
context: Context!,
clazz: Class<DownloadService!>!,
downloadRequest: DownloadRequest!,
stopReason: Int,
foreground: Boolean
): Intent!
Builds an Intent for adding a new download.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service being targeted by the intent. |
downloadRequest: DownloadRequest! |
The request to be executed. |
stopReason: Int |
An initial stop reason for the download, or |
foreground: Boolean |
Whether this intent will be used to start the service in the foreground. |
| Returns | |
|---|---|
Intent! |
The created intent. |
buildPauseDownloadsIntent
java-static fun buildPauseDownloadsIntent(
context: Context!,
clazz: Class<DownloadService!>!,
foreground: Boolean
): Intent!
Builds an Intent to pause all downloads.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service being targeted by the intent. |
foreground: Boolean |
Whether this intent will be used to start the service in the foreground. |
| Returns | |
|---|---|
Intent! |
The created intent. |
buildRemoveAllDownloadsIntent
java-static fun buildRemoveAllDownloadsIntent(
context: Context!,
clazz: Class<DownloadService!>!,
foreground: Boolean
): Intent!
Builds an Intent for removing all downloads.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service being targeted by the intent. |
foreground: Boolean |
Whether this intent will be used to start the service in the foreground. |
| Returns | |
|---|---|
Intent! |
The created intent. |
buildRemoveDownloadIntent
java-static fun buildRemoveDownloadIntent(
context: Context!,
clazz: Class<DownloadService!>!,
id: String!,
foreground: Boolean
): Intent!
Builds an Intent for removing the download with the id.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service being targeted by the intent. |
id: String! |
The content id. |
foreground: Boolean |
Whether this intent will be used to start the service in the foreground. |
| Returns | |
|---|---|
Intent! |
The created intent. |
buildResumeDownloadsIntent
java-static fun buildResumeDownloadsIntent(
context: Context!,
clazz: Class<DownloadService!>!,
foreground: Boolean
): Intent!
Builds an Intent for resuming all downloads.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service being targeted by the intent. |
foreground: Boolean |
Whether this intent will be used to start the service in the foreground. |
| Returns | |
|---|---|
Intent! |
The created intent. |
buildSetRequirementsIntent
java-static fun buildSetRequirementsIntent(
context: Context!,
clazz: Class<DownloadService!>!,
requirements: Requirements!,
foreground: Boolean
): Intent!
Builds an Intent for setting the requirements that need to be met for downloads to progress.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service being targeted by the intent. |
requirements: Requirements! |
A |
foreground: Boolean |
Whether this intent will be used to start the service in the foreground. |
| Returns | |
|---|---|
Intent! |
The created intent. |
buildSetStopReasonIntent
java-static fun buildSetStopReasonIntent(
context: Context!,
clazz: Class<DownloadService!>!,
id: String?,
stopReason: Int,
foreground: Boolean
): Intent!
Builds an Intent for setting the stop reason for one or all downloads. To clear the stop reason, pass STOP_REASON_NONE.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service being targeted by the intent. |
id: String? |
The content id, or |
stopReason: Int |
An application defined stop reason. |
foreground: Boolean |
Whether this intent will be used to start the service in the foreground. |
| Returns | |
|---|---|
Intent! |
The created intent. |
clearDownloadManagerHelpers
java-static fun clearDownloadManagerHelpers(): Unit
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.
onBind
fun onBind(intent: Intent!): IBinder?
Throws UnsupportedOperationException because this service is not designed to be bound.
sendAddDownload
java-static fun sendAddDownload(
context: Context!,
clazz: Class<DownloadService!>!,
downloadRequest: DownloadRequest!,
foreground: Boolean
): Unit
Starts the service if not started already and adds a new download.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
downloadRequest: DownloadRequest! |
The request to be executed. |
foreground: Boolean |
Whether the service is started in the foreground. |
sendAddDownload
java-static fun sendAddDownload(
context: Context!,
clazz: Class<DownloadService!>!,
downloadRequest: DownloadRequest!,
stopReason: Int,
foreground: Boolean
): Unit
Starts the service if not started already and adds a new download.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
downloadRequest: DownloadRequest! |
The request to be executed. |
stopReason: Int |
An initial stop reason for the download, or |
foreground: Boolean |
Whether the service is started in the foreground. |
sendPauseDownloads
java-static fun sendPauseDownloads(
context: Context!,
clazz: Class<DownloadService!>!,
foreground: Boolean
): Unit
Starts the service if not started already and pauses all downloads.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
foreground: Boolean |
Whether the service is started in the foreground. |
sendRemoveAllDownloads
java-static fun sendRemoveAllDownloads(
context: Context!,
clazz: Class<DownloadService!>!,
foreground: Boolean
): Unit
Starts the service if not started already and removes all downloads.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
foreground: Boolean |
Whether the service is started in the foreground. |
sendRemoveDownload
java-static fun sendRemoveDownload(
context: Context!,
clazz: Class<DownloadService!>!,
id: String!,
foreground: Boolean
): Unit
Starts the service if not started already and removes a download.
sendResumeDownloads
java-static fun sendResumeDownloads(
context: Context!,
clazz: Class<DownloadService!>!,
foreground: Boolean
): Unit
Starts the service if not started already and resumes all downloads.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
foreground: Boolean |
Whether the service is started in the foreground. |
sendSetRequirements
java-static fun sendSetRequirements(
context: Context!,
clazz: Class<DownloadService!>!,
requirements: Requirements!,
foreground: Boolean
): Unit
Starts the service if not started already and sets the requirements that need to be met for downloads to progress.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
requirements: Requirements! |
A |
foreground: Boolean |
Whether the service is started in the foreground. |
sendSetStopReason
java-static fun sendSetStopReason(
context: Context!,
clazz: Class<DownloadService!>!,
id: String?,
stopReason: Int,
foreground: Boolean
): Unit
Starts the service if not started already and sets the stop reason for one or all downloads. To clear stop reason, pass STOP_REASON_NONE.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
id: String? |
The content id, or |
stopReason: Int |
An application defined stop reason. |
foreground: Boolean |
Whether the service is started in the foreground. |
start
java-static fun start(context: Context!, clazz: Class<DownloadService!>!): Unit
Starts a download service to resume any ongoing downloads.
| Parameters | |
|---|---|
context: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
| See also | |
|---|---|
startForeground |
startForeground
java-static fun startForeground(context: Context!, clazz: Class<DownloadService!>!): Unit
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: Context! |
A |
clazz: Class<DownloadService!>! |
The concrete download service to be started. |
| See also | |
|---|---|
start |
Protected functions
getDownloadManager
protected abstract fun getDownloadManager(): DownloadManager!
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.
getForegroundNotification
protected abstract fun getForegroundNotification(
downloads: (Mutable)List<Download!>!,
@Requirements.RequirementFlags notMetRequirements: Int
): Notification!
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: (Mutable)List<Download!>! |
The current downloads. |
@Requirements.RequirementFlags notMetRequirements: Int |
Any requirements for downloads that are not currently met. |
| Returns | |
|---|---|
Notification! |
The foreground notification to display. |
getScheduler
protected abstract fun getScheduler(): Scheduler?
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
foregroundNotificationIdset toFOREGROUND_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
Scheduleris returned from this method, and the returnedSchedulersupportsall of the requirements that have been specified for downloads to continue, then the service will stop itself and theSchedulerwill be used to restart it in the foreground when the requirements are met. - If the device API level is less than 31 and either
nullor aSchedulerthat does notsupportall 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
Schedulercannot be used for this case due to Android 12 foreground service launch restrictions.
invalidateForegroundNotification
protected fun invalidateForegroundNotification(): Unit
Invalidates the current foreground notification and causes getForegroundNotification to be invoked again if the service isn't stopped.