3

I have a problem with facebook user login in my android application. I want users use their facebook account to login my system but when I click login button facebook native app starts and user enters email and password then native app closes and my app starts again. I dont want to use native app for this login proccess i want to open facebook login pop-up only like the other phones that does not have facebook native app.

How can i do this? thanks

Edit:

I use the methods below for login

protected void loginToFacebook()
{


    if( !mFacebook.isSessionValid() ) {
        Toast.makeText(mActivity, "logining", Toast.LENGTH_SHORT).show();
        mFacebook.authorize(mActivity,permissions, new LoginDialogListener());
    }
    else { 
        try {
            JSONObject json = Util.parseJson(mFacebook.request("me"));
            String facebookID = json.getString("id");
            String firstName = json.getString("first_name");
            String lastName = json.getString("last_name");
            String email = json.getString("email");
            Toast.makeText(mActivity,  mFacebook.getAccessToken()+email+"-" + firstName + " " + lastName + ". No need to re-authorize.", Toast.LENGTH_SHORT).show();

            appState.mFbToken = mFacebook.getAccessToken();
            appState.mFbEmail = email;
            mFacebookListener.onFacebookLoginSelected();

        }
        catch( Exception error ) {
            Toast.makeText( mActivity, error.toString(), Toast.LENGTH_SHORT).show();
        }
    }

}

For listening the response

public final class LoginDialogListener implements DialogListener {
    public void onComplete(Bundle values) {
        try {
            //The user has logged in, so now you can query and use their Facebook info
            JSONObject json = Util.parseJson(mFacebook.request("me"));
            String facebookID = json.getString("id");
            String firstName = json.getString("first_name");
            String lastName = json.getString("last_name");
            String email = json.getString("email");
            Toast.makeText( mActivity, mFacebook.getAccessToken() +email+"-" +  firstName + " " + lastName + "!", Toast.LENGTH_SHORT).show();
            SessionStore.save(mFacebook, mActivity);

            appState.mFbToken = mFacebook.getAccessToken();
            appState.mFbEmail = email;
            mFacebookListener.onFacebookLoginSelected();


        }
        catch( Exception error ) {
            Toast.makeText( mActivity, error.toString(), Toast.LENGTH_SHORT).show();
        }
    }

    public void onFacebookError(FacebookError error) {
        Toast.makeText( mActivity, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
    }

    public void onError(DialogError error) {
        Toast.makeText( mActivity, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
    }

    public void onCancel() {
        Toast.makeText( mActivity, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
    }
}

If native app starts my dialoglistenner does not work but if web based login pop-up starts my listenner works good.

Any Idea?

KAPLANDROID
  • 1,099
  • 1
  • 12
  • 23

4 Answers4

6

Please update below code of your application.

mFacebook.authorize(mActivity, permissions, Facebook.FORCE_DIALOG_AUTH,
            new LoginDialogListener());

instead of

mFacebook.authorize(mActivity, permissions, new LoginDialogListener());

And see below link for more information

Facebook Login Issue

Community
  • 1
  • 1
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
0

I'm sure this is possible, unfortunately I forgot how to do it. But as far as I remember the idea is that you should force the login dialog to appear. If I'm not mistaken a boolean parameter should be set to the dialog to force it appear.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
0

iOS and Android use something called Single Sign-on (SSO), which means anyone attempting to use Facebook in a 3rd Party app will launch the Facebook App for easier login. If the user has Facebook App installed, it will always launch the app for login - there is no way around it.

It's actually there for make it easier for the user. The user would usually be logged into the App already so using a 3rd Party FB App would only take a single touch / tap to authorise and use. You will find that user's without the FB app will see the web-based login page.

Niraj Shah
  • 15,087
  • 3
  • 41
  • 60
0

Don't enable SSO. This should resolve your problem.

Luke Taylor
  • 9,481
  • 13
  • 41
  • 73