6

I have an app which has been live for a couple of years now, but lately, I've been getting reports about the location system not functioning properly. I have tracked the issue down to the LocationCallback.onLocationAvailability(availability: LocationAvailability?). it is always called with availability.isLocationAvailable = false

The description indicates that it being false, means that i cannot count on getting any locations from the other function LocationCallback.onLocationResult(locationResult: LocationResult?) but the results tick in fine, and the position seems to be correct enough.

Can someone tell me if I can simply disregard the isLocationAvailable = false and just use the location results as they are, without taking any risks of getting false readings or or low accuracy or such?

I've tried with different settings for the LocationRequest, and there's no issue with any of them - except that the availability still gets called with false. The results themselves are fine.

Permissions are in place fair and square, I've also tried with ACCESS_FINE_LOCATION only, ACCESS_COARSE_LOCATION only and both on. Location are enabled on the devices.

Did something change about the inner workings of the FusedLocation system in the last few weeks? It's worked perfectly for years now?

Code:

var locationRequest: LocationRequest = LocationRequest.create().apply {
        interval = 10000
        fastestInterval = 5000
        priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY 
    }

When initializing and starting the location updates i use the following snip:

val locationClient = LocationServices.getFusedLocationProviderClient(this)
val builder = LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
val client: SettingsClient = LocationServices.getSettingsClient(this)
val task: Task<LocationSettingsResponse> = client.checkLocationSettings(builder.build())
task.addOnSuccessListener { locationSettingsResponse ->
    locationClient?.requestLocationUpdates(locationRequest, locationCallback, null)
}

And with this LocationCallback:

val locationCallback = object : LocationCallback() {
    override fun onLocationResult(locationResult: LocationResult?) {
        locationResult ?: return
        if (locationResult.locations.isNotEmpty()) {
            val location = locationResult.locations[0]
        }
    }
    override fun onLocationAvailability(availability: LocationAvailability?) {
         availability?.isLocationAvailable          <-- This is always false!
    }
}
Christian
  • 1,155
  • 8
  • 13

2 Answers2

9

This issue is caused by new Google Play services update (version 21.30.16).

See: https://issuetracker.google.com/issues/198176818

As per Sep 9, 2021 they say:

We have temporarily rolled back some of the logic around isLocationAvailable() and you should note behavior returning to normal over then next 24 hours or so.

Alex Balan
  • 226
  • 2
  • 4
  • Thanks - that's what I wanted to hear: I was right all along :-) – Christian Sep 10 '21 at 12:58
  • 4
    There's more in that issue log from google that probably is worth reading: https://issuetracker.google.com/issues/198176818#comment37 - which arguably renders that status of no value. –  Sep 10 '21 at 13:01
  • 1
    At least it gives a hint of what to expect. F.x. you do get a call with `true` or `false` when the user enables/disables location from settings. Which is very important. But currently, you get `false` in both cases: not acceptable. Well; hopefully, they'll have the update out soon. – Christian Sep 10 '21 at 13:12
  • 1
    But now all of our customers think it's our fault and lose faith in our systems... still broken a week later! – barnacle.m Sep 15 '21 at 21:56
  • Update: It is still not fixed as of Play Services release 21.33.14, even though it was promised to be solved "in 24 hours" – Christian Sep 17 '21 at 10:56
  • Still not fixed... – chillNZ Oct 04 '21 at 22:19
  • Not Fixed till now !!! – CHIRAG SAHU Dec 01 '22 at 13:35
-2

Your issue may be down to the updated GooglePlay policy regarding user location. The GDPR (General Data Protection Regulation), which came into force a few years ago, states that a user's location is personally identifiable information, so the user's consent is required now before you can use this data.

This just means that adding ACCESS_FINE_LOCATION / ACCESS_COARSE_LOCATION in the manifest permissions is not enough. You will need to request permission from the user at runtime.

See here and here for more information on requesting location permissions at runtime.

Kewi
  • 117
  • 1
  • 5
  • Thanks, but as I mentioned, the permissions are in place fair and square. That of course means the runtime permissions also. The issue is `onLocationAvailability(availability: LocationAvailability?)` callback. App-users have different options when location is available or not, and when the callback always tell me that it's not available, it is very difficult to provide clear feedback to the app-user. My best try to remedy this is to rely on the `onLocationResult`'s: If they start coming in, location-based features can be enabled in the app, and if they don't, I must disable those. – Christian Sep 10 '21 at 07:20