我的 LocationRequest 设置为 PRIORITY_HIGH_ACCURACY。但是在小米红米 Note 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 …Run Code Online (Sandbox Code Playgroud)