use of com.google.android.gms.common.api.ApiException in project FirebaseUI-Android by firebase.
the class AuthUI method delete.
/**
* Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
* API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
* fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
* silently.
*
* @param context the calling {@link Context}.
*/
@NonNull
public Task<Void> delete(@NonNull final Context context) {
final FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null) {
return Tasks.forException(new FirebaseAuthInvalidUserException(String.valueOf(CommonStatusCodes.SIGN_IN_REQUIRED), "No currently signed in user."));
}
final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
// Ensure the order in which tasks are executed properly destructures the user.
return signOutIdps(context).continueWithTask(task -> {
// Propagate exception if there was one
task.getResult();
if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
Log.w(TAG, "Google Play services not available during delete");
return Tasks.forResult((Void) null);
}
final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
List<Task<?>> credentialTasks = new ArrayList<>();
for (Credential credential : credentials) {
credentialTasks.add(client.delete(credential));
}
return Tasks.whenAll(credentialTasks).continueWith(task1 -> {
Exception e = task1.getException();
Throwable t = e == null ? null : e.getCause();
if (!(t instanceof ApiException) || ((ApiException) t).getStatusCode() != CommonStatusCodes.CANCELED) {
// doesn't mean fully deleting the user failed.
return task1.getResult();
}
return null;
});
}).continueWithTask(task -> {
// Propagate exception if there was one
task.getResult();
return currentUser.delete();
});
}
use of com.google.android.gms.common.api.ApiException in project FirebaseUI-Android by firebase.
the class GoogleSignInHandler method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode != RequestCodes.GOOGLE_PROVIDER) {
return;
}
try {
GoogleSignInAccount account = GoogleSignIn.getSignedInAccountFromIntent(data).getResult(ApiException.class);
setResult(Resource.forSuccess(createIdpResponse(account)));
} catch (ApiException e) {
if (e.getStatusCode() == CommonStatusCodes.INVALID_ACCOUNT) {
// If we get INVALID_ACCOUNT, it means the pre-set account was not available on the
// device so set the email to null and launch the sign-in picker.
mEmail = null;
start();
} else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CURRENTLY_IN_PROGRESS) {
// Hack for https://github.com/googlesamples/google-services/issues/345
// Google remembers the account so the picker doesn't appear twice for the user.
start();
} else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) {
setResult(Resource.forFailure(new UserCancellationException()));
} else {
if (e.getStatusCode() == CommonStatusCodes.DEVELOPER_ERROR) {
Log.w(TAG, "Developer error: this application is misconfigured. " + "Check your SHA1 and package name in the Firebase console.");
}
setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.PROVIDER_ERROR, "Code: " + e.getStatusCode() + ", message: " + e.getMessage())));
}
}
}
use of com.google.android.gms.common.api.ApiException 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