【发布时间】:2019-03-28 16:27:06
【问题描述】:
我正在使用以下代码显示弹出窗口以打开位置
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;
}
}
});
但有时即使用户点击 Ok 我也会得到响应 0 即 RESULT_CANCEL 在将播放服务更新到 16.0.0 后会发生这种情况
在 google issuetracker 上报告了这个错误,下面是关于它的更多详细信息的链接
【问题讨论】:
-
请发布您用于接收弹出结果的代码
-
你在 onActivityResult 中调用 super 吗?如果是这样,请尝试将其删除并告诉我是否可以解决您的问题
-
我有同样的问题,我发现有时它来到
onActivityResult并启动 NETWORK_PROVIDER && GPS_PROVIDER 结果正常,有时它导致取消并启动仅设备定位模式。这是我的问题stackoverflow.com/questions/53387741/…
标签: android google-play-services android-support-library android-location onactivityresult