codeomnitrix
codeomnitrix

Reputation: 4249

Facebook authentication via android app

I am new to android. I am developing an application which requires facebook login to proceed. So for this I have followed this tutorial - https://developers.facebook.com/docs/android/getting-started

EDIT: Using UILifecycleHelper, same thing happen, once user authenticates the application application is closed.

private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                Log.w("Vinit", "Session started");
              // make request to the /me API
              Request.newMeRequest(session, new Request.GraphUserCallback() {

                // callback after Graph API response with user object
                @Override
                public void onCompleted(GraphUser user, Response response) {
                  if (user != null) {
                    TextView t = (TextView) findViewById(R.id.textView1);
                    t.setText("User: " + user.getFirstName());

                  }
                }
              }).executeAsync();
            }
        }
    };

    private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() {
        @Override
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.d("HelloFacebook", String.format("Error: %s", error.toString()));
        }

        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.d("HelloFacebook", "Success!");
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);            
        if(new LoginChecker(this).isRegistered()){
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
        }else{
            setContentView(R.layout.activity_login);            
            LoginButton loginButton = (LoginButton) findViewById(R.id.loginButton1);
            thisActivity = this;
            loginButton.setOnClickListener(new OnClickListener() {                              
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub                  
                    uiHelper = new UiLifecycleHelper(thisActivity, callback);
                }
            });

        }
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          Log.w("Vinit", "On Activity Result function");
          uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback);
    }

Upvotes: 0

Views: 70

Answers (1)

klimat
klimat

Reputation: 24991

  1. Use UiLifecycleHelper https://developers.facebook.com/docs/reference/android/current/class/UiLifecycleHelper to be sure that your activity/fragment handle processing from facebook component in proper way.
  2. Check Facebook Session object. Does app call instructions inside session.IsOpened()? Try debug your code to see state of the Facebook Session.

Upvotes: 1

Related Questions