use of com.google.android.gms.common.api.ResolvableApiException in project coursera-android by aporter.
the class LocationGetLocationActivity method continueAcquiringLocations.
private void continueAcquiringLocations() {
// Start location services
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(POLLING_FREQ);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_FREQ);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);
// Used if needed to turn on settings related to location services
SettingsClient client = LocationServices.getSettingsClient(this);
Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
task.addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
// All location settings are satisfied. The client can initialize location requests here.
if (checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mLocationCallback = getLocationCallback();
mLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
// Schedule a runnable to stop location updates after a period of time
Executors.newScheduledThreadPool(1).schedule(new Runnable() {
@Override
public void run() {
mLocationClient.removeLocationUpdates(mLocationCallback);
}
}, MEASURE_TIME, TimeUnit.MILLISECONDS);
}
}
});
task.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception 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(LocationGetLocationActivity.this, 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 SignInKickstarter method start.
public void start() {
if (!TextUtils.isEmpty(getArguments().emailLink)) {
setResult(Resource.forFailure(new IntentRequiredException(EmailLinkCatcherActivity.createIntent(getApplication(), getArguments()), RequestCodes.EMAIL_FLOW)));
return;
}
// Signing in with Generic IDP puts the app in the background - it can be reclaimed by the
// OS during the sign in flow.
Task<AuthResult> pendingResultTask = getAuth().getPendingAuthResult();
if (pendingResultTask != null) {
pendingResultTask.addOnSuccessListener(authResult -> {
final IdpResponse response = new IdpResponse.Builder(new User.Builder(authResult.getCredential().getProvider(), authResult.getUser().getEmail()).build()).build();
handleSuccess(response, authResult);
}).addOnFailureListener(e -> setResult(Resource.forFailure(e)));
return;
}
// Only support password credentials if email auth is enabled
boolean supportPasswords = ProviderUtils.getConfigFromIdps(getArguments().providers, EmailAuthProvider.PROVIDER_ID) != null;
List<String> accountTypes = getCredentialAccountTypes();
// If the request will be empty, avoid the step entirely
boolean willRequestCredentials = supportPasswords || accountTypes.size() > 0;
if (getArguments().enableCredentials && willRequestCredentials) {
setResult(Resource.forLoading());
GoogleApiUtils.getCredentialsClient(getApplication()).request(new CredentialRequest.Builder().setPasswordLoginSupported(supportPasswords).setAccountTypes(accountTypes.toArray(new String[accountTypes.size()])).build()).addOnCompleteListener(task -> {
try {
handleCredential(task.getResult(ApiException.class).getCredential());
} catch (ResolvableApiException e) {
if (e.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
setResult(Resource.forFailure(new PendingIntentRequiredException(e.getResolution(), RequestCodes.CRED_HINT)));
} else {
startAuthMethodChoice();
}
} catch (ApiException e) {
startAuthMethodChoice();
}
});
} else {
startAuthMethodChoice();
}
}
use of com.google.android.gms.common.api.ResolvableApiException in project NightSkyGuide by MTBehnke.
the class MainActivity method startLocationUpdates.
private 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(MainActivity.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(MainActivity.this, "Location Services Unavailable", Toast.LENGTH_LONG).show();
useGPS = false;
SharedPreferences.Editor edit = preferences.edit();
edit.putBoolean("use_device_location", false);
edit.apply();
break;
}
}
});
}
Aggregations