Android 15 中前台服务类型的变更
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
We are making the following changes to foreground service types with Android
15.
- 要在清单中的以下位置声明的前台服务类型
android:foregroundServiceType
mediaProcessing
- 在清单中声明的权限
FOREGROUND_SERVICE_MEDIA_PROCESSING
- 要传递给
startForeground()
的常量
FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING
- 运行时前提条件
- 无
- 说明
用于对媒体资源执行耗时的操作(例如将媒体转换为其他格式)的服务。系统允许此服务运行的时间有限;在正常情况下,此时限为每天 24 小时中的 6 小时。(此限制由应用的所有 mediaProcessing
前台服务共享。)
在以下情况下,您的应用应手动停止媒体处理服务:
如果超时期限已到,系统会调用服务的 Service.onTimeout(int, int)
方法。此时,该服务有几秒钟的时间来调用 Service.stopSelf()
。如果服务未调用 Service.stopSelf()
,则会发生 ANR,并显示以下错误消息:“<fgs_type> 的前台服务未在超时时间内停止:<component_name>”。
注意:Service.onTimeout(int, int)
不适用于 Android 14 或更低版本。在搭载这些版本的设备上,如果媒体处理服务达到超时期限,系统会立即缓存应用。因此,您的应用不应等待收到超时通知。相反,它应在适当情况下尽快终止前台服务或将其更改为后台服务。
相机
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.
数据同步
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.
麦克风
以 Android 14(API 级别 34)或更高版本为目标平台的应用不得通过 BOOT_COMPLETED
广播接收器启动麦克风前台服务。如需了解详情,请参阅对启动前台服务的 BOOT_COMPLETED
广播接收器的限制。
通话
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.
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],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)."]]