this is the problem
private fun checkDeviceLocationSettingsAndGetLocationUpdates(resolve: Boolean = true) {
val locationRequest = com.google.android.gms.location.LocationRequest.create().apply {
priority = LocationRequest.QUALITY_LOW_POWER
}
val builder = LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
val settingsClint = LocationServices.getSettingsClient(requireActivity())
val locationSettingsResponseTask = settingsClint.checkLocationSettings(builder.build())
locationSettingsResponseTask.addOnFailureListener { exeption ->
if (exeption is ResolvableApiException && resolve) {
try {
startIntentSenderForResult(
exeption.resolution.intentSender,
REQUEST_TURN_DEVICE_LOCATION_ON,
null,
0, 0, 0,
null
)
} catch (sendEx: IntentSender.SendIntentException) {
Log.d(TAG, "Error geting location settings resolution: " + sendEx.message)
}
} else {
Snackbar.make(
this.requireView(),
"Location services must be enabled to use the app", Snackbar.LENGTH_INDEFINITE
).setAction(android.R.string.ok) {
checkDeviceLocationSettingsAndGetLocationUpdates()
}.show()
}
}
locationSettingsResponseTask.addOnCompleteListener {
if (it.isSuccessful) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0.0f, locationListener
)
}
}
}
I am using the google services library to check Location setting if it was enabled or not
if the location is ON the location update request will be triggered
else it will ask the user to enable it and then trigger the location update request
if the services are not available nothing will happen and no location update will be requested
so I will try another way to check the location feature