
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d("TAG", "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
String userID = mAuth.getCurrentUser().getUid();
String userName = mAuth.getCurrentUser().getDisplayName();
String userEmail = mAuth.getCurrentUser().getEmail();
DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users");
Map newPost = new HashMap();
newPost.put("userName", userName);
newPost.put("userEmail", userEmail);
current_user_db.setValue(newPost);
} else {
// If sign in fails, display a message to the user.
Log.w("TAG", "signInWithCredential:failure", task.getException());
Toast.makeText(SignUpActivity.this, "Authentication failed.",
Toast.LENGTH_LONG).show();
// updateUI(null);
}
// ...
}
});
}
Подробнее здесь: https://stackoverflow.com/questions/498 ... g-firebase