gpt4 book ai didi

android - 在检查位置设置的情况下,即使用户按下 'OK"按钮,也始终获取 RESOLUTION_REQUIRED

转载 作者:行者123 更新时间:2023-12-03 13:41:54 27 4
gpt4 key购买 nike

我的 LocationRequest 设置为 PRIORITY_HIGH_ACCURACY。但是在小米红米 Note 5 设备中,如果我在位置设置对话框中按下确定按钮,它总是通过 onActivityResult() 方法返回 0,并且我得到“com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED”。但我已经在其他一些设备上进行了测试,它工作正常。我在 fragment 中使用了这个启用/未启用的 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) {

}


}

最佳答案

我找到了一些链接:https://stackoverflow.com/a/58331118
检查您的位置请求对象。
我在使用的时候,

mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
它反复触发 com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED异常(exception)。
当我改为,
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
它工作正常。
请尝试并发布您的更新。

关于android - 在检查位置设置的情况下,即使用户按下 'OK"按钮,也始终获取 RESOLUTION_REQUIRED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55529370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com