Changes to foreground service types for Android 15
Stay organized with collections
Save and categorize content based on your preferences.
We are making the following changes to foreground service types with Android
15.
- Foreground service type to declare in manifest under
android:foregroundServiceType
mediaProcessing
- Permission to declare in your manifest
FOREGROUND_SERVICE_MEDIA_PROCESSING
- Constant to pass to
startForeground()
FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING
- Runtime prerequisites
- None
- Description
Service for performing time-consuming operations on media assets, like
converting media to different formats. The system allows this service a limited
time to run; under normal circumstances, this time limit would be 6 hours out of
every 24. (This limit is shared by all of an app's mediaProcessing
foreground
services.)
Your app should manually stop the media processing service in the following
scenario:
If the timeout period is reached, the system calls the service's
Service.onTimeout(int, int)
method. At this
time, the service has a few
seconds to call Service.stopSelf()
. If the service does not call
Service.stopSelf()
, an ANR will occur with this error message: "A
foreground service of <fgs_type> did not stop within its
timeout: <component_name>".
Note: Service.onTimeout(int, int)
is not available on Android 14
or lower. On devices running those versions, if a media processing
service reaches the timeout period, the system immediately caches the app.
For this reason, your app shouldn't wait to get a timeout notification.
Instead, it should terminate the foreground service or change it to a
background service as soon as appropriate.
Camera
Apps that target Android 15 or higher are not allowed to launch a
camera foreground service from a BOOT_COMPLETED
broadcast receiver.
For more information, see
Restrictions on BOOT_COMPLETED
broadcast receivers launching foreground
services.
Data sync
Apps that target Android 15 or higher are not allowed to launch a
data sync foreground service from a BOOT_COMPLETED
broadcast receiver.
For more information, see
Restrictions on BOOT_COMPLETED
broadcast receivers launching foreground
services.
Apps that target Android 15 or higher are not allowed to launch a
media playback foreground service from a BOOT_COMPLETED
broadcast receiver.
For more information, see
Restrictions on BOOT_COMPLETED
broadcast receivers launching foreground
services.
Apps that target Android 15 or higher are not allowed to launch a
media projection foreground service from a BOOT_COMPLETED
broadcast receiver.
For more information, see
Restrictions on BOOT_COMPLETED
broadcast receivers launching foreground
services.
Microphone
Apps that target Android 14 (API level 34) or higher are not allowed to launch a
microphone foreground service from a BOOT_COMPLETED
broadcast receiver.
For more information, see
Restrictions on BOOT_COMPLETED
broadcast receivers launching foreground
services.
Phone call
Apps that target Android 15 or higher are not allowed to launch a
phone call foreground service from a BOOT_COMPLETED
broadcast receiver.
For more information, see
Restrictions on BOOT_COMPLETED
broadcast receivers launching foreground
services.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-05-15 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-15 UTC."],[],[],null,["# Changes to foreground service types for Android 15\n\nWe are making the following changes to foreground service types with Android\n15.\n\n### Media processing\n\nForeground service type to declare in manifest under\n`android:foregroundServiceType`\n: `mediaProcessing`\n\nPermission to declare in your manifest\n: `FOREGROUND_SERVICE_MEDIA_PROCESSING`\n\nConstant to pass to `startForeground()`\n: `FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING`\n\nRuntime prerequisites\n: None\n\nDescription\n\n: Service for performing time-consuming operations on media assets, like\n converting media to different formats. The system allows this service a limited\n time to run; under normal circumstances, this time limit would be 6 hours out of\n every 24. (This limit is shared by all of an app's `mediaProcessing` foreground\n services.)\n\n: Your app should manually stop the media processing service in the following\n scenario:\n\n - When the transcoding operation finishes or reaches a failure state, have the service call [`Service.stopForeground()`](/reference/android/app/Service#stopForeground(int)) and [`Service.stopSelf()`](/reference/android/app/Service#stopSelf()) to stop the service completely.\n\n: If the timeout period is reached, the system calls the service's\n [`Service.onTimeout(int, int)`](/reference/android/app/Service#onTimeout(int,%20int)) method. At this\n time, the service has a few\n seconds to call [`Service.stopSelf()`](/reference/android/app/Service#stopSelf()). If the service does not call\n `Service.stopSelf()`, an ANR will occur with this error message: \"A\n foreground service of *\\\u003cfgs_type\\\u003e* did not stop within its\n timeout: *\\\u003ccomponent_name\\\u003e*\".\n\n **Note** : `Service.onTimeout(int, int)` is not available on Android 14\n or lower. On devices running those versions, if a media processing\n service reaches the timeout period, the system immediately caches the app.\n For this reason, your app shouldn't wait to get a timeout notification.\n Instead, it should terminate the foreground service or change it to a\n background service as soon as appropriate.\n\n### Camera\n\nApps that target Android 15 or higher are not allowed to launch a\ncamera foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Data sync\n\nApps that target Android 15 or higher are not allowed to launch a\ndata sync foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Media playback\n\nApps that target Android 15 or higher are not allowed to launch a\nmedia playback foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Media projection\n\nApps that target Android 15 or higher are not allowed to launch a\nmedia projection foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Microphone\n\nApps that target Android 14 (API level 34) or higher are not allowed to launch a\nmicrophone foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Phone call\n\nApps that target Android 15 or higher are not allowed to launch a\nphone call foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed)."]]