I have the problem that when I open my app and I call the permissions dialog using startResolutionForResult() and click no thanks there I get this dialog popping up over and over again until I click Om. How can I prevent this behavior so that when the user clicks No Thanks, the dialog disappears and only reappears when the user clicks a button ect?
The whole thing only happens in the onResume method. So I call showEnableLocationSetting() when I click on a button ect and then say no, everything works as it should
override fun onResume() {
super.onResume()
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
showEnableLocationSetting()
}
}
private fun showEnableLocationSetting() {
this?.let {
val locationRequest = LocationRequest.create()
locationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY
val builder = LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest)
val task = LocationServices.getSettingsClient(it)
.checkLocationSettings(builder.build())
task.addOnSuccessListener { response ->
val states = response.locationSettingsStates
if (states!!.isLocationPresent) {
//Do something
}
}
task.addOnFailureListener { e ->
if (e is ResolvableApiException) {
try {
// Called until the user presses Ok. No thanks will be ignored
e.startResolutionForResult(it,
200)
} catch (sendEx: IntentSender.SendIntentException) { }
}
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (200) {
RESULT_OK -> {
startLocationUpdates()
}
RESULT_CANCELED->{
return
}
}
}