// [START auth_with_google]
  private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE]
    showProgressDialog();
    // [END_EXCLUDE]
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth
        .signInWithCredential(credential)
        .addOnCompleteListener(
            this,
            new OnCompleteListener<AuthResult>() {
              @Override
              public void onComplete(@NonNull Task<AuthResult> task) {
                Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                // If sign in fails, display a message to the user. If sign in succeeds
                // the auth state listener will be notified and logic to handle the
                // signed in user can be handled in the listener.
                if (!task.isSuccessful()) {
                  Log.w(TAG, "signInWithCredential", task.getException());
                  Toast.makeText(
                          GoogleSignInActivity.this, "Authentication failed.", Toast.LENGTH_SHORT)
                      .show();
                }
                // [START_EXCLUDE]
                hideProgressDialog();
                // [END_EXCLUDE]
              }
            });
  }
 @Override
 @WorkerThread
 @Nullable
 public FirebaseUser signInWithCredential(@NonNull AuthCredential credential) {
   Task<AuthResult> curTask = mFirebaseAuth.signInWithCredential(credential);
   AuthResult authResult = await(curTask);
   return authResult == null ? null : authResult.getUser();
 }
Ejemplo n.º 3
0
 private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
   AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
   mAuth
       .signInWithCredential(credential)
       .addOnCompleteListener(
           this,
           new OnCompleteListener<AuthResult>() {
             @Override
             public void onComplete(@NonNull Task<AuthResult> task) {
               if (!task.isSuccessful()) {
                 Toast.makeText(
                         SignInActivity.this, R.string.erro_google_sign_in, Toast.LENGTH_SHORT)
                     .show();
               }
             }
           });
 }