private void onSessionStateChange(Session session, SessionState state, Exception exception) {
   Log.d(TAG, "onSessionStateChange!");
   if (isResumed) {
     Log.d(TAG, "is resumed!");
     FragmentManager manager = getSupportFragmentManager();
     int backStackSize = manager.getBackStackEntryCount();
     for (int i = 0; i < backStackSize; i++) {
       manager.popBackStack();
     }
     // check for the OPENED state instead of session.isOpened() since for the
     // OPENED_TOKEN_UPDATED state, the selection fragment should already be showing.
     if (state.equals(SessionState.OPENED)) {
       Log.d(TAG, "onSessionStateChange: Logged to facebook");
       Intent i = new Intent(LoginActivity.this, MainActivity.class);
       startActivityForResult(i, REQUEST_CODE_FACEBOOK_LOGIN);
     } else if (state.isClosed()) {
       // NO logged to facebook
       Log.d(TAG, "onSessionStateChange: Not logged to facebook");
     }
   }
 }
Beispiel #2
0
  // <editor-fold desc="Facebook Methods">
  private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (isResumed) {

      // check for the OPENED state instead of session.isOpened() since for the
      // OPENED_TOKEN_UPDATED state, the selection fragment should already be showing.
      if (state.equals(SessionState.OPENED)) {

        if (registered) sendAccessTokenToBackend(session.getAccessToken());

        Request.executeMeRequestAsync(
            session,
            new Request.GraphUserCallback() {
              @Override
              public void onCompleted(GraphUser user, Response response) {
                if (user != null) {
                  Log.i("FB User Id ", user.getId());
                  PreferenceManager.getDefaultSharedPreferences(a)
                      .edit()
                      .putInt("login_method", FACEBOOK_LOGIN)
                      .commit();
                  setContentView(R.layout.activity_start);
                  // LoadData();
                  Session session = Session.getActiveSession();
                  if (session != null && session.isOpened()) makeMeRequest(session);
                }
              }
            });
      } else if (state.isClosed()) {
        PreferenceManager.getDefaultSharedPreferences(a)
            .edit()
            .putInt("login_method", NO_METHOD_DEFINED)
            .commit();
        setContentView(R.layout.activity_login_only_facebook);
      }
    }
  }