2017-04-13 62 views
0

我使用LocationSettingsRequest要求用戶啓用以下位置是我的代碼如何取消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; 
      } 
     } 
    }); 

它創建一個對話框,我想取消對話框片段停止如何做到這一點有是因爲它

回答

0

我不承擔任何方法,你不應該叫

status.startResolutionForResult(getActivity(), REQUEST_CHECK_SETTINGS); 

這將防止GPServi ces不會顯示對話框,但您必須自己處理狀態。