vendredi 29 mai 2015

Login button facebook android doesn't redirect to new activity

When i run my Android app, and click approve to the give permissions it not get redirected to the MainActivity. The "Logged in" message doesn't shows up in the Catlog. I have read the Facebook developers guide, and compared my code to different topics here at Stack. I can't see i have done anything wrong.

I would be very glad for help.

public class Login extends Activity {

/**
 * Called when the activity is first created.
 */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    final CallbackManager callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile", "email", "user_friends");


    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            callbackManager.onActivityResult(requestCode, resultCode, data);
        }



        @Override
        public void onSuccess(LoginResult loginResult) {

            Intent i = new Intent(Login.this, MainActivity.class);
            startActivity(i);
            System.out.print("Logged in");

        }

        @Override
        public void onCancel() {
            // App code

        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            Log.i("Error" , "Error");
            }


        });
    }
}

Aucun commentaire:

Enregistrer un commentaire