Is there any way to know if LocationSettingsStatusCodes is equal to RESOLUTION_REQUIRED without having to call mSettingsClient.checkLocationSettings all the time? May be from location object of onLocationChanged listener?
mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(mActivity,
new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
Log.i(this.getClass().getName(), "Location settings ok");
mFusedProviderClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper()).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
});
}
}).addOnFailureListener(mActivity, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
if(statusCode == LocationSettingsStatusCodes.RESOLUTION_REQUIRED){
//Location settings not satisfied.
try {
// Cast to a resolvable exception.
ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(
mActivity,
AppCommand.REQUEST_GOOGLE_ACCURACY);
} catch (IntentSender.SendIntentException ex) {
Log.e(this.getClass().getName(), "SendIntentException " + e.getLocalizedMessage());
}
}
Log.e(this.getClass().getName(), "Check location permission failed: " +e.getLocalizedMessage());
}
}
);
if LocationSettingsStatusCodes is equal to RESOLUTION_REQUIRED
This is not true.
LocationSettingsStatusCodes
is not equal to RESOLUTION_REQUIRED
.
LocationSettingsStatusCodes
is an encapsulation of the failure exception handling mechanism, but other exceptions may occur in the actual process,and We cannot guarantee what other conditions may cause the permission check to fail.