Android 如何取消在LocationSettingsRequest上创建的对话框
我正在使用LocationSettingsRequest请求用户启用位置,以下是我的代码Android 如何取消在LocationSettingsRequest上创建的对话框,android,google-play-services,android-location,Android,Google Play Services,Android Location,我正在使用LocationSettingsRequest请求用户启用位置,以下是我的代码 LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest); PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
final LocationSettingsStates locationSettingsStates = locationSettingsResult.getLocationSettingsStates();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:// All location settings are satisfied. The client can initialize location requests here.
//mGoogleApiClient.connect();
startLocationUpdates();
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:// Location settings are not satisfied, but this can be fixed by showing the user a dialog.
try {
status.startResolutionForResult(getActivity(), REQUEST_CHECK_SETTINGS);// Show the dialog by calling startResolutionForResult(), and check the result in onActivityResult().
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();// 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;
}
}
});
LocationSettingsRequest.Builder=新建LocationSettingsRequest.Builder().addLocationRequest(MLLocationRequest);
PendingResult=LocationServices.SettingsApi.checkLocationSettings(mgoogleAppClient,builder.build());
result.setResultCallback(新的ResultCallback(){
@凌驾
public void onResult(@NonNull LocationSettingsResult LocationSettingsResult){
最终状态状态=locationSettingsResult.getStatus();
final LocationSettingsStates LocationSettingsStates=locationSettingsResult.getLocationSettingsStates();
开关(status.getStatusCode()){
案例位置SettingsStatusCodes.SUCCESS://满足所有位置设置。客户端可以在此处初始化位置请求。
//mGoogleApiClient.connect();
startLocationUpdates();
打破
案例位置SettingsStatusCodes.RESOLUTION_REQUIRED://不满足位置设置,但可以通过向用户显示对话框来解决此问题。
试一试{
status.startResolutionForResult(getActivity(),REQUEST_CHECK_SETTINGS);//通过调用startResolutionForResult()显示对话框,并在onActivityResult()中检查结果。
}catch(IntentSender.sendtintentexe){
e、 printStackTrace();//忽略错误。
}
打破
案例位置SettingsStatusCodes.SETTINGS\u CHANGE\u UNAVAILABLE://位置设置不满足要求。但是,我们无法修复设置,因此不会显示对话框。
打破
}
}
});
它创建了一个对话框我想取消对话框是片段停止了怎么做没有方法
status.startResolutionForResult(getActivity(), REQUEST_CHECK_SETTINGS);
这将阻止GPServices显示该对话框,但您必须自己处理该状态