Authentication with Facebook and Google in Firebase - Android Studio

0

I'm developing an Android application, with Android Studio, using Firebase initially for user authentication.

The code is too long, so I will not copy it here, but it's available at Github .

The Google login has already been implemented, the user logs in, goes to the home screen where they choose a room, and when they enter the room, a chat window appears where they can send messages, including photos and profile names Of google.

I'm now implementing a Facebook login based on the Firebase and Facebook , I have already followed all the setup steps on developers.facebook.com, such as application id, key hash etc, plus the creation of the login button with Facebook.

The login is practically functional, the user enters with his account through the standard window of Facebook, however when finishing the login, the application returns to the initial screen. That is, it takes the information but does not go to the next activity (the MainActivity, where the rooms are).

I and the other developers of the app are students and beginners in Android programming, so I think it's something simple but we can not fix it. For being beginners also ask that if someone answers, please explain in what file would be the modification, the tutorial of Facebook is a bit vague about it. Thank you very much in advance.

    
asked by anonymous 21.04.2017 / 00:46

1 answer

1

// This method is called in 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();
        }
    });
}
    
08.06.2017 / 14:56