My LocationRequest is set to PRIORITY_HIGH_ACCURACY. But in xiaomi redmi note 5 device if i press the ok button in the location settings dialog it always returns 0 through onActivityResult() method and i get "com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED". But i have tested in some other devices it works fine. I have used this gps enabled/not enabled checking inside a fragment.
/////Code that prompts up the dialog
SettingsClient client = LocationServices.getSettingsClient(getActivity ());
Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
task.addOnSuccessListener(getActivity (), new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
// All location settings are satisfied. The client can initialize
// location requests here.
// ...
}
});
task.addOnFailureListener(getActivity (), new OnFailureListener () {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof ResolvableApiException) {
// Location settings are not satisfied, but this can be fixed
// by showing the user a dialog.
try {
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(getActivity (),
REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sendEx) {
// Ignore the error.
}
}
}
});
/////// onActivityResult() method inside my fragment
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
super.onActivityResult (requestCode, resultCode, data);
switch (resultCode) {
case -1:
requestLocationUpdates ();
break;
case 0:
displayLocationSettingsRequest (getContext ());
break;
default:
super.onActivityResult (requestCode, resultCode, data);
break;
}
} catch (Exception ex) {
}
}
I found some link: https://stackoverflow.com/a/58331118
Check your location request object. When I'm using,
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
it's repeatedly fires com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED
exception.
When I changed to,
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
it's working fine.
Please give a try and post your updates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With