ExoPlayer
ExoPlayer copied to clipboard
Error while trying to use Downloadservice for background download on android 12
ExoPlayer Version
2.16.1
Devices that reproduce the issue
Pixel 4A
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Not tested
Reproduction steps
Tried to use the DownloadService for downloading content while the app is in the background using push.
Expected result
It works in all the android versions except android 12
Actual result
android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service
Media
Any content .
Bug Report
- [ ] You will email the zip file produced by
adb bugreportto [email protected] after filing this issue.
Android 12 introduces new restrictions on starting a foreground service from the background.
ExoPlayer's DownloadService keeps itself in the foreground while waiting for requirement to be met (e.g. internet connection), but you can't start it from the background from Android 12 onwards.
Android 12 introduces new restrictions on starting a foreground service from the background.
ExoPlayer's
DownloadServicekeeps itself in the foreground while waiting for requirement to be met (e.g. internet connection), but you can't start it from the background from Android 12 onwards.
@tonihei, Thank you for the reply. So, what would be your suggestion in case I want to use ExoPlayer for background download?
It depends what action starts your download and whether it falls under the exceptions that are allowed to start a foreground service from the background:
- If the download is started by a user action, you should already be in a foreground service / activity and there shouldn't be an issue starting the download service.
- If the download is triggered by an action external to the device (e.g. a user asking to download something on another device) you could use a high-priority Firebase Cloud Message to start the service. This is allowed per the exceptions linked above.
- If the download should be scheduled based on timing (e.g. download latest episodes once a day), you essentially need to find one of the exceptions to start the download. For example, Firebase Cloud Messages are an option again, exact alarms should work, or you could prompt your users to disable battery optimizations (which they may want to grant if you explain the reason is to download in the background).
Closing because I don't think there is anything else we can do here.