Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SettingsClient returns failure when Location is enabled on device #398

Open
forecasty1 opened this issue Apr 26, 2020 · 0 comments
Open

Comments

@forecasty1
Copy link

forecasty1 commented Apr 26, 2020

Facing issue with SettingsClient.
Due to https://developer.android.com/training/location/change-location-settings i did following request to ask user enable location when its disabled:

settingsClient.checkLocationSettings(locationSettingsRequest.build())
            .addOnSuccessListener {
                viewModel.locationPermissionGranted()
            }
            .addOnFailureListener {
                if (it is ResolvableApiException) {
                    try {
                        it.startResolutionForResult(
                            fragment.activity,
                           RESULT_CODE_LOCATION
                        )
                    } catch (sendEx: IntentSender.SendIntentException) {
                        ...
                    }
                }
            }

First issue here that onFailure() is called when location is enabled on device(but in this case onSuccessListener should be called).

Bad, but then user still will see dialog to enable location and after he taps "OK", i am trying to request location updates :

**// ITS ALWAYS TRUE**
 if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) ||
            locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
        ) {
            val callback = object : LocationCallback() {
                override fun onLocationResult(locationResult: LocationResult?) {
                    locationClient.removeLocationUpdates(this) ....
                }

                override fun onLocationAvailability(p0: LocationAvailability?) {
                    super.onLocationAvailability(p0)
                 **// BUT ALWAYS APPEAR HERE with p0.isLocationAvailable==false**
                }
            }

            locationClient.requestLocationUpdates(
                locationRequest,
                callback,
                Looper.myLooper()
            )
        } 

So second issue that even locationManager.isProviderEnabled(GPS||NETWORK) always returns true (so location enabled as it is), but just onLocationAvailability(p0: LocationAvailability?) is called (where p0.isLocationAvailable==false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant