Sha*_*kib 9 android android-gps google-location-services
我的 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 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) {
}
}
Run Code Online (Sandbox Code Playgroud)
我找到了一些链接:https ://stackoverflow.com/a/58331118
检查您的位置请求对象。当我使用时,
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Run Code Online (Sandbox Code Playgroud)
它反复引发com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED异常。
当我改为,
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
Run Code Online (Sandbox Code Playgroud)
工作正常。
请尝试并发布您的更新。
| 归档时间: |
|
| 查看次数: |
1123 次 |
| 最近记录: |