'Android LocationManager: unexpected behavior in Android 12
Users in the field are reporting random problems with GPS location in an app. The app has been using LocationManager for about 12 years with little modification.
I was able to see some unpredictable behavior by testing on Pixel 3 with Android 12. The behavior includes location being off by half a mile, and not updating regularly unless some other app uses GPS.
Are there some things that are different about location manager in Android 11/12? If so where are they documented? The code I have has worked fine since Android 1.5.
I am using it through a library, but decompiling gave me this call:
mLocationManager.requestLocationUpdates("gps", 250, 1, listener);
I changed it to
mLocationManager.requestLocationUpdates("gps", 100, 0, listener);
It worked for a bit and then stopped working again. The updates don't come in.
Does it need background location even though the documentation says I SHOULDN'T need background location to use location in an activity or foreground service?
If not, what the heck is going on?
Solution 1:[1]
Weve seen the same problem @nathanMDT which we logged initially with the SDK we thought was at fault, link below. The problem is Android 12 specifically and a change they made about a month ago to some google map permissions, all the relevant articles can be found in the below post. The devs dropped an update about 3 days ago in this tracker which im hoping will help. First response was "wait till Android 13". As a side note downgrading to Android 11 instantly fixes the frequency updates - not that this helps much.
Solution 2:[2]
Foreground services still require background location permissions to access location. That's because its non obvious to the user that just because there's a notification there that it's still using GPS. And yes, this was added in Android 11: https://developer.android.com/guide/components/foreground-services#bg-access-restrictions
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Luke |
| Solution 2 | Gabe Sechan |
