title: addOnFailureListener() doesnot call if user once enabled and after sometime disable location. when using LocationServices.getSettingsClient()
body: <ol>
  <li>I have used <code>LocationServices.getSettingsClient()</code> to remove depricated<br />
  <code>LocationServices.SettingsApi.checkLocationSettings()</code>.</li>
  <li>It is asking user to enable location
  first time when mainActivity launch if location is disabled.</li>
  <li>If in between i disable location . it is not asking to enable location. means<br />
  <code>result.addOnSuccessListener</code> is called even if my location is disabled.</li>
  <li>if Location is disabled inbetweeen it should ask <code> result.addOnFailureListener</code></li>
  </ol>
  <pre><code>mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getContext());
          mSettingsClient = LocationServices.getSettingsClient(getContext());
          LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
          builder.addLocationRequest(mLocationRequest);
          mLocationSettingsRequest = builder.build();
          mLocationService = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
          Task&lt;LocationSettingsResponse&gt; result =
                  LocationServices.getSettingsClient(getContext()).checkLocationSettings(builder.build());
    result.addOnSuccessListener(getActivity(), new OnSuccessListener&lt;LocationSettingsResponse&gt;() {
              @Override
              public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
                 
                LocationSettingsResponse response =
                              task.getResult(ApiException.class);
  
                      LocationSettingsStates locationSettingsStates = response.getLocationSettingsStates();
                      if (!locationSettingsStates.isGpsPresent() || !locationSettingsStates.isGpsUsable()) {
            //check point 4 
              }
          });
  
          result.addOnFailureListener(getActivity(), new OnFailureListener() {
              @Override
              public void onFailure(@NonNull Exception e) {
                  if (e instanceof ResolvableApiException) {
                      // Location settings are not satisfied, but this can be fixed
                      // by showing the user a dialog.
                      try {
                          // Show the dialog by calling startResolutionForResult(),
                          // and check the result in onActivityResult().
                          ResolvableApiException resolvable = (ResolvableApiException) e;
                          resolvable.startResolutionForResult(getActivity(),
                                  REQUEST_CHECK_SETTINGS);
                      } catch (IntentSender.SendIntentException sendEx) {
                          // Ignore the error.
                      }
                  }
              }
          }); 
  
  </code></pre>
  <ol start="4">
  <li>here I want need to open location enabling dialog using following code:</li>
  </ol>
  <pre><code>final Status status = result.getStatus();
              switch (status.getStatusCode()) {
                  case LocationSettingsStatusCodes.SUCCESS:
                      Log.i(TAG, &quot;All location settings are satisfied.&quot;);
                      break;
                  case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                      Log.i(TAG, &quot;Location settings are not satisfied. Show the user a dialog to upgrade location settings &quot;);
  
                      try {
                          // Show the dialog by calling startResolutionForResult(), and check the result
                          // in onActivityResult().
                          status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
                      } catch (IntentSender.SendIntentException e) {
                          Log.i(TAG, &quot;PendingIntent unable to execute request.&quot;);
                      }
                      break;
                  case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                      Log.i(TAG, &quot;Location settings are inadequate, and cannot be fixed here. Dialog not created.&quot;);
                      break;
              }
  </code></pre>
  <p>5 .but using <code>SettingsClient</code> <code>onSucess</code> gives
  <code>Task&lt;LocationSettingsResponse&gt; result</code> which does not give statusCode that I recieve in catch block</p>
  <p><strong>Update</strong></p>
  <p>First Tag is try part of <code>OnComplete()</code> when location is by default on
  second time I turn off location and go to other <code>Fragment</code> and again came to main fragment.
  Tt executed try part even I location was disabled</p>
  <p><a href="https://i.stack.imgur.com/UtkrH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UtkrH.png" alt="enter image description here" /></a></p>