在后台访问位置信息
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
按照请求位置信息权限和隐私设置最佳实践页面中所述,应用应该只请求获得实现面向用户的功能所必需的位置信息权限,并以恰当的方式向用户披露请求的内容。大多数使用情形中,只有在用户与应用互动时才需要使用位置信息。如果您的应用需要在后台访问位置信息(例如在实现地理围栏时),请确保这种访问对使用应用的核心功能起到至关重要的作用,能为用户提供明确的好处,并且采用一种让用户清楚知道的方式完成。
注意:Google Play 商店已更新有关设备位置信息的政策,限制应用仅在实现核心功能所必需的情形下且在满足相关政策要求后才能请求后台位置信息访问权限。采用这些最佳实践并不能保证 Google Play 会批准您的应用在后台使用位置信息。
详细了解与设备位置信息相关的政策变更。
后台位置信息访问权限核对清单
请使用以下核对清单确定潜在的后台位置信息访问逻辑:
评估后台位置信息访问权限
如果您发现应用在后台访问了位置信息,请考虑执行以下操作:
- 评估后台位置信息访问权是否对应用的核心功能起到至关重要的作用。
如果您不需要在后台访问位置信息,请移除此权限。
如果您的应用以 Android 10(API 级别 29)或更高版本为目标平台,请从应用的清单中移除 ACCESS_BACKGROUND_LOCATION
权限。移除此权限后,搭载 Android 10 的设备上的应用将无法选择始终访问位置信息。
确保用户知道您的应用在后台访问位置信息。在用户不能明显察觉的情形下,这一点尤为重要。
如果可能,请重构您的位置信息访问逻辑,以便仅在用户可以看到应用的活动时请求访问位置信息。
限制后台位置信息更新次数
如果后台位置信息访问权限对您的应用至关重要,请注意:在搭载 Android 8.0(API 级别 26)及更高版本的设备上,Android 系统为了延长设备电池的续航时间,采用了“后台位置信息限制”的设置。在这些版本的 Android 系统中,如果您的应用在后台运行,它每小时只能接收几次位置信息更新。详细了解后台位置信息限制。
其他资源
如需详细了解关于后台位置信息的使用,请查看以下资料:
视频
如何查找可能在后台使用位置信息的情况
示例
此示例演示了应用在后台运行时访问位置信息的最佳实践。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Access location in the background\n\nAs described on the [request location\npermissions](/training/location/permissions) and [privacy best\npractices](/privacy/best-practices) pages, apps should only ask for the type of\nlocation permission that's critical to the user-facing feature, and properly\ndisclose this to users. The majority of use cases only require location when the\nuser is engaging with the app. If your app requires background location, such as\nwhen implementing geofencing, make sure that it's critical to the core\nfunctionality of the app, offers clear benefits to the user, and is done in a\nway that's obvious to them. \n**Note:** The Google Play store has updated its policy concerning device\nlocation, restricting background location access to apps that need it for\ntheir core functionality and meet related policy requirements. Adopting these\nbest practices doesn't guarantee Google Play approves your app's usage of\nlocation in the background.\n\nLearn more about the\n[policy\nchanges](https://support.google.com/googleplay/android-developer/answer/9799150) related to device location.\n\nBackground location access checklist\n------------------------------------\n\nUse the following checklist to identify potential location access logic in the\nbackground:\n\n- In your app's manifest, check for the\n [`ACCESS_COARSE_LOCATION` permission](/reference/android/Manifest.permission#ACCESS_COARSE_LOCATION)\n and the\n [`ACCESS_FINE_LOCATION` permission](/reference/android/Manifest.permission#ACCESS_FINE_LOCATION).\n Verify that your app requires these location permissions.\n\n - If your app targets Android 10 (API level 29) or higher, also check for the [`ACCESS_BACKGROUND_LOCATION`\n permission](/training/location/receive-location-updates#request-background-location). Verify that your app has a feature that requires it.\n- Look for use of location access APIs, such as the [Fused Location Provider\n API](https://developers.google.com/location-context/fused-location-provider),\n [Geofencing API](https://developers.google.com/location-context/geofencing), or\n [LocationManager API](/reference/android/location/LocationManager), within your\n code such as in the following constructs:\n\n - [Background services](/training/run-background-service/create-service)\n - [`JobIntentService`](/reference/kotlin/androidx/core/app/JobIntentService) objects\n - [`WorkManager`](/reference/kotlin/androidx/work/WorkManager) or [`JobScheduler`](/reference/kotlin/android/app/job/JobScheduler) tasks\n - [`AlarmManager`](/reference/kotlin/android/app/AlarmManager) operations\n - Pending intents that are invoked from an [app\n widget](/guide/topics/appwidgets)\n- If your app uses an SDK or library that accesses location, this access is\n attributed to your app. To determine whether an SDK or library needs location\n access, consult the library's documentation.\n\nEvaluate background location access\n-----------------------------------\n\nIf you find that your app accesses location in the background, consider taking\nthe following actions:\n\n- Evaluate whether background location access is critical to the core functionality of the app.\n- If you don't need location access in the background, remove it.\n\n If your app targets Android 10 (API level 29) or higher, remove the\n [`ACCESS_BACKGROUND_LOCATION`\n permission](/training/location/receive-location-updates#request-background-location)\n from your app's manifest. When you remove this permission, all-the-time\n access to location isn't an option for the app on devices that run\n Android 10.\n- Make sure the user is aware that your app is accessing location in the\n background. This is especially important for cases that aren't obvious to users.\n\n- If possible, [refactor your location access\n logic](/about/versions/oreo/background-location-limits#tuning-behavior) so that\n you request location only when your app's activity is visible to users.\n\nLimited updates to background location\n--------------------------------------\n\nIf background location access is essential for your app, keep in mind that\nAndroid preserves device battery life by setting *background location\nlimits* on devices that run Android 8.0 (API level 26) and higher. On these\nversions of Android, if your app is running in the background, it can receive\nlocation updates only a few times each hour. Learn more about [background\nlocation limits](/about/versions/oreo/background-location-limits).\n\nAdditional resources\n--------------------\n\nTo learn more about background location usage, view the following materials:\n\n### Videos\n\n[How to find possible background location\nusage](https://www.youtube.com/watch?v=xTVeFJZQ28c)\n\n### Samples\n\n[Sample](https://github.com/android/platform-samples/tree/main/samples/location/src/main/java/com/example/platform/location/bglocationaccess)\nto demonstrate best practices for accessing location when app is in background."]]