Search in sources :

Example 1 with ApiException

use of com.google.android.gms.common.api.ApiException in project Grupp by tmoronta1208.

the class LoginActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w("TAG", "Google sign in failed", e);
            Toast.makeText(this, "Auth went wrong :(", Toast.LENGTH_SHORT).show();
        // ...
        }
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 2 with ApiException

use of com.google.android.gms.common.api.ApiException in project google-services by googlesamples.

the class RestApiActivity method handleSignInResult.

private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
    Log.d(TAG, "handleSignInResult:" + completedTask.isSuccessful());
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        updateUI(account);
        // Store the account from the result
        mAccount = account.getAccount();
        // Asynchronously access the People API for the account
        getContacts();
    } catch (ApiException e) {
        Log.w(TAG, "handleSignInResult:error", e);
        // Clear the local account
        mAccount = null;
        // Signed out, show unauthenticated UI.
        updateUI(null);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 3 with ApiException

use of com.google.android.gms.common.api.ApiException in project google-services by googlesamples.

the class ServerAuthCodeActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_GET_AUTH_CODE) {
        // [START get_auth_code]
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            String authCode = account.getServerAuthCode();
            // Show signed-un UI
            updateUI(account);
        // TODO(developer): send code to server and exchange for access/refresh/ID tokens
        } catch (ApiException e) {
            Log.w(TAG, "Sign-in failed", e);
            updateUI(null);
        }
    // [END get_auth_code]
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 4 with ApiException

use of com.google.android.gms.common.api.ApiException in project Devsfolio by Madonahs.

the class LoginActivity method handleGoogleSignInResult.

/**
 * Handles google sign in result
 *
 * @param completedTask - completed GoogleSignInAccount task
 */
private void handleGoogleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        // Successfully signed in
        if (account != null) {
            // TODO: All user's basic info such as name can now be obtained from the account object
            String personName = account.getDisplayName();
            String personEmail = account.getEmail();
            // For debugging purposes only
            Log.d(TAG, "Google info " + personName + " - " + personEmail);
            // Start MainActivity
            Intent mainActivityIntent = new Intent(getBaseContext(), MainActivity.class);
            // TODO: User info can be passed in to the MainActivity as EXTRA or stored locally in db or Firebase
            startActivity(mainActivityIntent);
        }
    } catch (ApiException e) {
        // Google sign in failed
        e.printStackTrace();
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) Intent(android.content.Intent) ApiException(com.google.android.gms.common.api.ApiException)

Example 5 with ApiException

use of com.google.android.gms.common.api.ApiException 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;
                }
            }
        }
    });
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) LocationSettingsResponse(com.google.android.gms.location.LocationSettingsResponse) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) ApiException(com.google.android.gms.common.api.ApiException)

Aggregations

ApiException (com.google.android.gms.common.api.ApiException)28 GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)15 ResolvableApiException (com.google.android.gms.common.api.ResolvableApiException)10 LocationSettingsResponse (com.google.android.gms.location.LocationSettingsResponse)9 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)7 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)6 LocationRequest (com.google.android.gms.location.LocationRequest)5 LocationSettingsRequest (com.google.android.gms.location.LocationSettingsRequest)5 IntentSender (android.content.IntentSender)4 Intent (android.content.Intent)3 NonNull (androidx.annotation.NonNull)3 FirebaseAuthInvalidUserException (com.google.firebase.auth.FirebaseAuthInvalidUserException)3 Bundle (android.os.Bundle)2 TextUtils (android.text.TextUtils)2 Nullable (androidx.annotation.Nullable)2 UserCancellationException (com.firebase.ui.auth.data.model.UserCancellationException)2 AuthMethodPickerActivity (com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity)2 ExtraConstants (com.firebase.ui.auth.util.ExtraConstants)2 GoogleApiUtils (com.firebase.ui.auth.util.GoogleApiUtils)2 ProviderUtils (com.firebase.ui.auth.util.data.ProviderUtils)2