shekhar23/claude-zero-to-hero-android-kmp/android-background-location-geofencing
Claude Code and agent skill by shekhar23/claude-zero-to-hero-android-kmp
- community
Checking that the SKILL.md file is still in the repository.
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".
Install
npx vskill@latest install shekhar23/claude-zero-to-hero-android-kmp/android-background-location-geofencingSKILL.md
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:
ACCESS_FINE_LOCATIONorACCESS_COARSE_LOCATION— required first.ACCESS_BACKGROUND_LOCATION— can only be requested after the foreground permission is granted.
Declare in AndroidManifest.xml:
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 explicitly:
Launch foreground first, background only after foreground is granted:
On Android 11+, requesting ACCESS_BACKGROUND_LOCATION opens the system settings screen, not a dialog. Explain this to the user before launching.
Foreground Service for Continuous Tracking
Declare the service in the manifest with foregroundServiceType:
The service class:
Do not run location updates in a CoroutineWorker without a foreground service — WorkManager workers are not guaranteed to stay alive for continuous streaming.
LocationRequest: Accuracy and Battery Trade-offs
| Priority | Battery use | Accuracy | When to use | |
|---|---|---|---|---|
PRIORITY_HIGH_ACCURACY | High | GPS-level | Turn-by-turn navigation | |
PRIORITY_BALANCED_POWER_ACCURACY | Medium | ~100 m | Delivery tracking, fitness | |
PRIORITY_LOW_POWER | Low | City-level | Background city-aware features | |
PRIORITY_PASSIVE | Minimal | Opportunistic | Logging only, no urgency |
setMinUpdateDistanceMeters is the most impactful battery saving for stationary or slow-moving users. Always set it unless sub-meter precision is required at rest.
FusedLocationProviderClient Setup
Wrap the client behind a data-layer interface:
The @SuppressLint("MissingPermission") annotation is acceptable here because permission checks happen in the presentation layer before starting the service. Never call these APIs without a prior permission check.
Geofencing API
Setup
BroadcastReceiver
Register the receiver in the manifest:
Do not do heavy processing directly in onReceive — it runs on the main thread with a short time budget. Delegate to a coroutine scope, a service, or WorkManager.
Re-registering Geofences After Reboot
Geofences are cleared when the device reboots or the app is updated. Re-register on:
BOOT_COMPLETEDbroadcast- App process restart if the data layer detects missing fences
Anti-Patterns
- Requesting
ACCESS_BACKGROUND_LOCATIONwithout a clearly user-visible reason — triggers Play Store review scrutiny. - Using
PRIORITY_HIGH_ACCURACYfor passive or periodic use cases — drains the battery unnecessarily. - Not calling
removeLocationUpdateswhen the service stops — keeps GPS hardware active. - Storing raw
Locationobjects in the domain layer — map to typed domain models with lat/lng/accuracy/timestamp. - Ignoring geofence
GEOFENCE_STATUS_OPERATION_NOT_AVAILABLE— the device may not support geofencing; degrade gracefully. - Re-registering geofences on every app launch without checking if they are already active — wastes resources and can hit the 100-geofence limit.
Testing Guidance
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/android-background-location-geofencing/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/shekhar23/claude-zero-to-hero-android-kmp/android-background-location-geofencing)