【问题标题】:How to cancel dialog created on LocationSettingsRequest如何取消在 LocationSettingsRequest 上创建的对话框
【发布时间】:2017-09-09 08:25:13
【问题描述】:

我正在使用 LocationSettingsRequest 要求用户启用位置以下是我的代码

 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;
            }
        }
    });

它创建了一个对话框我想取消对话框是片段被停止了怎么做没有办法

【问题讨论】:

    标签: android google-play-services android-location


    【解决方案1】:

    我认为你不应该打电话

    status.startResolutionForResult(getActivity(), REQUEST_CHECK_SETTINGS);
    

    这将阻止 GPServices 显示对话框,但您必须自己处理状态。

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 2015-02-03
      • 2012-12-19
      相关资源
      最近更新 更多