gpt4 book ai didi

android - LocationSettingsRequest 返回 0 到 onActivityResult 即使点击确定

转载 作者:可可西里 更新时间:2023-11-01 18:49:11 27 4
gpt4 key购买 nike

我正在使用以下代码显示弹出窗口以打开位置

        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
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.
// ...
getUserLocation();
}
});

task.addOnFailureListener(getActivity(), new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
Log.d("AMOD", "onFailure " + statusCode);
switch (statusCode) {
case CommonStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied, but this can be fixed
// by showing the user a dialog.
try {

ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(getActivity(),
REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sendEx) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way
// to fix the settings so we won't show the dialog.
break;
}
}
});

代码如下它显示如下弹出窗口 enter image description here

但有时即使用户点击确定,我也会收到 resposne 0 即 RESULT_CANCEL 将播放服务更新到 16.0.0 后会发生这种情况

在 google issuetracker 上报告了这个错误,下面是有关它的更多详细信息的链接

https://issuetracker.google.com/issues/118347902

最佳答案

我只是尝试了大约 50 次来重现这个,我总是得到代码 -1(运行 Android Pie 的 Pixel 3)。但是我在运行 Oreo 的 Nexus 5x 上大约有一半时间为 0。

我不能准确地找出你做错了什么,但这是我做的一个示例项目,它做同样的事情并且每次都能正常工作:

https://github.com/gavingt/basic_location_improved

关于android - LocationSettingsRequest 返回 0 到 onActivityResult 即使点击确定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52965886/

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