Skip to content

SettingsClient returns failure when Location is enabled on device #398

Open
@forecasty1

Description

@forecasty1

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions