← ClaudeAtlas

android-background-location-geofencinglisted

Background location and geofencing patterns for Android - FusedLocationProviderClient setup, foreground vs background location permission flows, foreground service for continuous tracking, GeofencingClient with broadcast receivers, battery-aware accuracy strategies, and graceful permission denial handling. Use this skill whenever implementing continuous location tracking, geofence entry/exit events, or any feature requiring ACCESS_BACKGROUND_LOCATION. Trigger on phrases like "background location", "geofence", "location tracking", "FusedLocationProvider", "ACCESS_BACKGROUND_LOCATION", "location foreground service", or "track location".
lenorebreakneck630/claude-zero-to-hero-android-KMP · ★ 1 · DevOps & Infrastructure · score 64
Install: claude install-skill lenorebreakneck630/claude-zero-to-hero-android-KMP
# Android Background Location and Geofencing ## Core Principles - Foreground location and background location are separate permission tiers — request them independently and in sequence. - Continuous tracking requires a Foreground Service with `foregroundServiceType="location"`. - Geofences are battery-efficient; prefer them over polling when the requirement is proximity-based. - Battery accuracy must match the actual product need — do not default to `PRIORITY_HIGH_ACCURACY`. - Location code in the data layer; permission state and UI decisions in the presentation layer. --- ## Permission Tiers Android enforces a two-step permission model for background location: 1. `ACCESS_FINE_LOCATION` or `ACCESS_COARSE_LOCATION` — required first. 2. `ACCESS_BACKGROUND_LOCATION` — can only be requested *after* the foreground permission is granted. Declare in `AndroidManifest.xml`: ```xml <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <!-- Required for Android 14+ foreground location service --> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" /> ``` **Do not** request `ACCESS_BACKGROUND_LOCATION` in the same launcher call as the foreground permission. The system ignores or rejects bundled requests on Android 11+. --- ## Permission Flow in Compose Model all states explici