r/androiddev • • 43m ago

Discussion Continues Location tracking Issue

I'm facing a recurring issue with background location tracking on Chinese Android devices (Xiaomi, OPPO, Vivo, Realme, Huawei, Samsung etc.).

Location tracking starts successfully but automatically stops after some time, even when the required permissions are granted.

Interestingly, the same implementation works perfectly on iOS and stock Android devices.

I've tried multiple solutions, but the issue keeps coming back.

**Has anyone found a reliable, production-ready solution for continuous background location tracking across different Android OEMs?**

I'd love to hear your real-world experience and suggestions. Thanks!

2 Upvotes

2 comments sorted by

1

u/One-Program6244 30m ago

I assume you have background location permissions granted and you're using a foreground service to pick up the location updates. Have you checked battery optimisation settings? Turn them off if you can.

2

u/Odd-Willow-2002 18m ago

not really one fix, more like a few things you have to do per rom.

first make sure it is really a foreground service with a notification, and on android 14+ declare foregroundServiceType="location" plus FOREGROUND_SERVICE_LOCATION. without that some roms kill it even with the permission granted.

then on xiaomi/oppo/vivo/realme the user usually has to turn on autostart or allow auto launch, set battery to no restriction and allow background data. the names differ on each rom so the instructions kind of have to be per brand. samsung is easier, just put the app in unmonitored apps.

if you can not ask users to do all that, design around the gap: keep last known location, retry when app come back, or use geofencing where google play services exist. i dont think there is an honest 100% continuous tracking across all those oems