Android 11 中的前台服务
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 Android 11 中,前台服务何时可以访问设备的位置信息、摄像头和麦克风发生了一些变化。这有助于保护敏感的用户数据。
- 前台服务类型 camera 和 microphone
- 如果您的应用以 Android 11 或更高版本为目标平台,且在前台服务中访问摄像头或麦克风,则必须添加前台服务类型
camera
和 microphone
。
- 对在使用时访问的限制
- 如果您的应用在后台运行时启动了某项前台服务,则该前台服务无法访问麦克风或摄像头。此外,除非您的应用具有在后台访问位置信息的权限,否则该服务无法访问位置信息。
详细了解如何在应用中使用前台服务。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Foreground services in Android 11\n\nAndroid 11 changes when foreground services can\naccess the device's location, camera, and microphone. This helps protect\nsensitive user data.\n\nCamera and microphone foreground service types\n: If your app targets Android 11 or higher and accesses the\n camera or microphone in a foreground service, you must include the `camera` and\n `microphone` [foreground service\n types](/guide/components/foreground-services#types).\n\nRestrictions to access while in use\n: If your app [starts a foreground service while running in the\n background](/guide/components/foreground-services#while-in-use-restrictions), the\n foreground service cannot access the microphone or camera. Additionally,\n the service cannot access location unless your app\n has [background location](/training/location/permissions#background) access.\n\nLearn more about how to use [foreground\nservices](/guide/components/foreground-services) in your app."]]