Authentication with Facebook and Google in Firebase-Android Studio

I am developing an Android app, with Android Studio, using Firebase initially for user authentication.

The code is quite extensive, so I won't copy it here, but it's available on GitHub.

Has already been implemented the login with Google, the user logs in, goes to the Home screen where he chooses a room and, when entering the room, a chat window appears where he can send messages, including already with photo and name of Google profile.

Facebook facebook login is now implemented according to the tutorials of Firebase and Facebook , I have already followed all the configuration steps in developers.facebook.com, such as App id, key hash etc, in addition to creating the login button with Facebook.

The login is Practically Functional, the user enters with his account through the default Facebook window, but when logging out, the application returns to the Home screen. That is, it takes the information but does not go to the next activity (the MainActivity, where the rooms are).

Me and the other developers of the app are students and beginners in Android programming, so I believe it is something simple but we are not able to fix it. Because we are beginners I also ask that if someone answers, please explain in which file would be the modification, the Facebook tutorial is kind of vague about it. I appreciate it now.

Author: Leila, 2017-04-20

1 answers

/ / this eh method called on the onClick of the face button

private void loginFacebookResult() {     
buttonFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            handlerFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException e) {
            Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
        }

    });
}  
private void handlerFacebookAccessToken(AccessToken accessToken) {

    AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken());
    mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {

            showProgressDialog();

            if (!task.isSuccessful()) {
                Log.w("Facebook Message:", "signInWithCredential", task.getException());
                Toast.makeText(LoginActivity.this, "Erro de Login", Toast.LENGTH_SHORT).show();
            } else {
                Usuario user = new Usuario();
                user.setId(mAuth.getCurrentUser().getUid());
                user.setNome(mAuth.getCurrentUser().getDisplayName());
                user.setEmail(mAuth.getCurrentUser().getEmail());

User.setUrl (mAuth.getCurrentUser ().getPhotoUrl().toString()); user.saveBD ();

                Intent intentMain = new Intent(LoginActivity.this, (sua classe destino).class);
                startActivity(intentMain);
            }

            hideProgressDialog();
        }
    });
}
 1
Author: Anderson Alencar, 2017-06-08 12:56:55