0
Ola, I need to adjust the app I’m developing so there’s notification whenever GPS is disabled. When the app starts, if the GPS is disabled, it alerts and then starts the Switch to location settings. I happen to be using the requestLocationUpdates method of the Fusedlocationproviderclient class and, after it is started, if I disable the GPS nothing happens because 'apparently' it gets 'stuck' in the method as if it were in Loop.
NOTE: Even changing the method Looper.getMainLooper() to null in the argument of requestLocationUpdates the problem persists
This is the method that checks the GPS
private fun verificarServicoLocalizacao(): Boolean {
val ativo: Boolean
val gl: LocationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
if(gl.isProviderEnabled(LocationManager.GPS_PROVIDER)){
ativo = true
}else{
Toast.makeText(this, R.string.ativar_localizacao, Toast.LENGTH_LONG).show()
val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
startActivity(intent)
ativo = false
}
return ativo
}
This is the method that requests the location
private fun novaLocalizacao() {
val locationRequest = LocationRequest()
locationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY
locationRequest.interval = 2000
locationRequest.fastestInterval = 1000
mFusedLocationClient.requestLocationUpdates(locationRequest,
locationCallback, Looper.getMainLooper())
}