A chat app for Android. Uses Firebase Realtime Database and one touch sign in with Google Authentication.
-
Download google-services.json from the settings menu in firebase console.
-
Copy the file to the correct app module project directory.
The class is instanciated by calling getInstance().
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mAuth = FirebaseAuth.getInstance();
...
}
- Right after the listener has been registered
- When a user is signed in
- When the current user is signed out
- When the current user changes
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() != null){
startActivity(new Intent(SignInActivity.this, ContactsActivity.class));
}
}
};
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> 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();
//updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w("TAG", "signInWithCredential:failure", task.getException());
, Snackbar.LENGTH_SHORT).show();
//updateUI(null);
}
}
});
}