我的LocationRequest设置为PRIORITY_HIGH_ACCURACY。但是在小米Redmi注意事项5设备中,如果我在位置设置对话框中按“确定”按钮,则它始终会通过onActivityResult()方法返回0,并且会收到“ com.google.android.gms.common.api.ResolvableApiException:6:RESOLUTION_REQUIRED”。但是我已经在其他一些设备上进行了测试,效果很好。我已经在片段中使用了启用/未启用此gps的功能。
/////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) {
}
}
答案 0 :(得分:0)
我找到了一些链接:https://stackoverflow.com/a/58331118
检查您的位置请求对象。 当我使用时,
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
它反复触发 com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED
异常。
当我改成,
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
一切正常。
请尝试并发布您的更新。