Mengakses lokasi di latar belakang
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Seperti yang dijelaskan di halaman meminta izin akses lokasi dan praktik terbaik privasi, aplikasi sebaiknya hanya meminta jenis izin akses lokasi yang benar-benar diperlukan oleh fitur yang digunakan pengguna, dan mengungkapkan hal ini dengan benar kepada pengguna. Sebagian besar kasus penggunaan hanya memerlukan lokasi saat pengguna berinteraksi dengan aplikasi. Jika aplikasi Anda memerlukan lokasi latar belakang, seperti saat menerapkan pembatasan wilayah, pastikan bahwa akses tersebut benar-benar diperlukan oleh fungsi inti aplikasi, menawarkan manfaat yang jelas bagi pengguna, dan dilakukan dengan cara yang jelas.
Catatan: Google Play Store telah memperbarui kebijakannya terkait lokasi perangkat, pembatasan akses lokasi latar belakang ke aplikasi yang memerlukannya untuk fungsi utamanya, dan memenuhi persyaratan kebijakan terkait. Menggunakan praktik terbaik ini tidak menjamin Google Play menyetujui penggunaan lokasi aplikasi Anda di latar belakang.
Pelajari perubahan kebijakan lebih lanjut terkait lokasi perangkat.
Checklist akses lokasi latar belakang
Gunakan checklist berikut untuk mengidentifikasi kemungkinan logika akses lokasi di latar belakang:
Mengevaluasi akses lokasi latar belakang
Jika ternyata aplikasi Anda mengakses lokasi di latar belakang, pertimbangkan untuk melakukan tindakan berikut:
- Evaluasi apakah akses lokasi latar belakang benar-benar diperlukan oleh fungsi inti aplikasi.
Jika tidak memerlukan akses lokasi di latar belakang, hapus akses.
Jika aplikasi Anda menargetkan Android 10 (API level 29) atau yang lebih baru, hapus izin ACCESS_BACKGROUND_LOCATION
dari manifes aplikasi Anda. Jika izin ini dihapus, akses lokasi sepanjang waktu tidak dapat digunakan untuk aplikasi di perangkat yang menjalankan Android 10.
Pastikan pengguna mengetahui bahwa aplikasi Anda mengakses lokasi di latar belakang. Hal ini sangat penting untuk kasus yang tidak jelas bagi pengguna.
Jika memungkinkan, faktorkan ulang logika akses
lokasi sehingga
Anda hanya meminta lokasi saat aktivitas aplikasi dapat dilihat oleh pengguna.
Pembaruan terbatas pada lokasi latar belakang
Jika akses lokasi latar belakang sangat penting untuk aplikasi Anda, perlu diingat bahwa Android mempertahankan masa pakai baterai perangkat dengan menetapkan batas lokasi latar belakang di perangkat yang menjalankan Android 8.0 (API level 26) dan yang lebih baru. Pada versi Android ini, jika aplikasi Anda berjalan di latar belakang, aplikasi hanya dapat menerima pembaruan lokasi beberapa kali setiap jam. Pelajari batas lokasi latar belakang lebih lanjut.
Referensi lainnya
Untuk mempelajari penggunaan lokasi latar belakang lebih lanjut, lihat materi berikut:
Video
Cara menemukan kemungkinan penggunaan lokasi
latar belakang
Contoh
Contoh
untuk menunjukkan praktik terbaik dalam mengakses lokasi saat aplikasi berada di latar belakang.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[null,null,["Terakhir diperbarui pada 2025-07-27 UTC."],[],[],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."]]