use of com.google.android.gms.common.api.ResolvableApiException in project Instafood by Gear61.
the class LocationManager method checkLocationServicesAndFetchLocationIfOn.
private void checkLocationServicesAndFetchLocationIfOn() {
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
SettingsClient client = LocationServices.getSettingsClient(activity);
client.checkLocationSettings(builder.build()).addOnSuccessListener(new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
fetchAutomaticLocation();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
if (exception instanceof ResolvableApiException) {
locationServicesManager.askForLocationServices(LOCATION_SERVICES_CODE);
} else {
onLocationFetchFail();
}
}
});
}
use of com.google.android.gms.common.api.ResolvableApiException in project Instafood by Gear61.
the class LocationServicesManager method askForLocationServices.
void askForLocationServices(final int requestCode) {
Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(activity).checkLocationSettings(locationBuilder.build());
result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
@Override
public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
try {
task.getResult(ApiException.class);
} catch (ApiException exception) {
switch(exception.getStatusCode()) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
ResolvableApiException resolvable = (ResolvableApiException) exception;
// Show dialog to turn on location services
resolvable.startResolutionForResult(activity, requestCode);
} catch (IntentSender.SendIntentException | ClassCastException ignored) {
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
openLocationSettings();
break;
}
}
}
});
}
use of com.google.android.gms.common.api.ResolvableApiException in project NightSkyGuide by MTBehnke.
the class SettingsActivity method startLocationUpdates.
public void startLocationUpdates() {
// if settings are satisfied initialize location requests
mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
locUpdates = true;
// All location settings are satisfied.
// noinspection MissingPermission - this comment needs to stay here to stop inspection on next line
mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
switch(statusCode) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// 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(SettingsActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sendEx) {
// Ignore the error
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// location settings are not satisfied, however no way to fix the settings so don't show dialog.
Toast.makeText(context, "Location Services Unavailable", Toast.LENGTH_LONG).show();
useGPS = false;
SharedPreferences.Editor edit = preferences.edit();
edit.putBoolean("use_device_location", false);
edit.apply();
settingsFragment.useDeviceLocation.setChecked(false);
settingsFragment.setLocSummary();
break;
}
}
});
}
use of com.google.android.gms.common.api.ResolvableApiException in project routerkeygenAndroid by routerkeygen.
the class NetworksListActivity method settingsRequest.
public static void settingsRequest(final Activity activity, OnSuccessListener cb) {
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(100000);
mLocationRequest.setFastestInterval(50000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
SettingsClient client = LocationServices.getSettingsClient(activity);
Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
task.addOnSuccessListener(activity, cb);
task.addOnFailureListener(activity, e -> {
int statusCode = ((ApiException) e).getStatusCode();
switch(statusCode) {
case CommonStatusCodes.RESOLUTION_REQUIRED:
// 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(activity, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sendEx) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// to fix the settings so we won't show the dialog.
break;
}
});
}
use of com.google.android.gms.common.api.ResolvableApiException in project FirebaseUI-Android by firebase.
the class SmartLockHandlerTest method testSaveCredentials_resolution.
@Test
public void testSaveCredentials_resolution() {
mHandler.getOperation().observeForever(mResultObserver);
// Mock credentials to throw an RAE
ResolvableApiException mockRae = mock(ResolvableApiException.class);
when(mMockCredentials.save(any(Credential.class))).thenReturn(AutoCompleteTask.forFailure(mockRae));
// Kick off save
mHandler.saveCredentials(TestHelper.getMockFirebaseUser(), TestConstants.PASSWORD, null);
InOrder inOrder = inOrder(mResultObserver);
inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
// Make sure we get a resolution
ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());
// Call activity result
PendingIntentRequiredException e = ((PendingIntentRequiredException) resolveCaptor.getValue().getException());
mHandler.onActivityResult(e.getRequestCode(), Activity.RESULT_OK);
// Make sure we get success
inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
Aggregations