在背景中存取位置資訊
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要求位置存取權和隱私權最佳做法等頁面所述,應用程式如需要求位置存取權,必須是面向使用者的核心功能,並應適當向使用者揭露這項資訊。在多數情況下,只有在使用者與應用程式互動時才需要位置資訊。如果應用程式需要背景位置資訊 (例如實作地理圍欄時),請確保該項資訊對於應用程式的核心功能至關重要,且對使用者明顯有利,並以顯而易見的方式完成。
注意:Google Play 商店已更新規範裝置位置資訊的政策,針對需要背景位置存取權才能執行核心功能且符合相關政策規定的應用程式,設定相關限制。採用這些最佳做法,並不能保證 Google Play 核准您的應用程式在背景使用位置資訊。
進一步瞭解裝置位置資訊相關的政策異動。
背景位置資訊存取權檢查清單
請使用下列檢查清單找出潛在的背景位置資訊存取權邏輯:
評估背景位置資訊存取權
如果您發現自己的應用程式在背景存取位置資訊,建議您採取下列做法:
- 評估背景位置資訊存取權是否對於應用程式的核心功能至關重要。
如果不需要在背景存取位置資訊,請將背景位置資訊存取權移除。
如果應用程式指定的是 Android 10 (API 級別 29) 以上版本,請從應用程式的資訊清單中移除 ACCESS_BACKGROUND_LOCATION
權限。移除這項權限後,應用程式就無法在搭載 Android 10 的裝置上選擇「一律允許」位置資訊存取權。
確認使用者知道您的應用程式會在背景存取位置資訊。這在使用者不易察覺這種狀況時特別重要。
盡可能重構位置資訊存取邏輯,讓應用程式只有在使用者看得到應用程式的活動時,才要求位置資訊。
有限的背景位置資訊更新
如果應用程式必須存取背景位置資訊,請謹記系統會在搭載 Android 8.0 (API 級別 26) 以上版本的裝置上設定「背景位置資訊限制」,藉此延長 Android 裝置的電池續航力。在這類 Android 版本中,如果應用程式在背景執行,每小時只能接收數次的位置更新。進一步瞭解背景位置資訊限制。
其他資源
如要進一步瞭解背景位置資訊的使用方式,請參閱下列資料:
影片
如何找出可能在使用背景位置資訊的情形
範例
歡迎參考範例,瞭解應用程式在背景執行時,存取位置資訊的最佳做法。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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."]]