title: Facebook Session.openActiveSessionWithAccessToken is not working even with a valid token in Android
body: <p>I'm working with Android and the Facebook API, basically, what I want is to create an alarm that do some Facebook stuff every certain time, even when the user has booted his device and the application is not running in the system.</p>
  
  <p>I have my FacebookLoginFragment that is doing the login perfectly with the Facebook Login button this way:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      loginDone = false;
  
      uiHelper = new UiLifecycleHelper(getActivity(), callback);
      uiHelper.onCreate(savedInstanceState);
  
      Session.setActiveSession(new Session.Builder(getActivity().getBaseContext()).setApplicationId(getString(R.string.app_id)).build());
  
      return inflater.inflate(R.layout.fragment_facebook_login, container, false);
  }
  </code></pre>
  
  <p>This is working, and this is the handler:</p>
  
  <pre><code>private void onSessionStateChange(Session session, SessionState state, Exception exception) {
      if (session.isOpened()) {
          SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext);
          SharedPreferences.Editor editor = sharedPreferences.edit();
  
          if (session.getAccessToken() != null)
              editor.putString("com.facebook.sdk.AccessToken", session.getAccessToken());
  
          if (session.getExpirationDate()!= null)
              editor.putLong("com.facebook.sdk.AccessTokenExpires", session.getExpirationDate().getTime());
  
          editor.commit();
  
          if (!loginDone) {
              loginDone = true;
              startActivity(new Intent(getActivity(), UpdateSnitchListActivity.class));
          }
      }
  }
  </code></pre>
  
  <p>What I'm doing after the user is authorizing the application is to save the auth token. Then, in my BroadcastReceiver I want to access Facebook stuff but it's failing:</p>
  
  <pre><code>public class MyBootReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
              Log.i("ALARM", "MyBootReceiver is executing when device boots");
              SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
  
              if (sharedPreferences.getBoolean(context.getString(R.string.preference_use_service), true)) {
                  if (Session.getActiveSession() == null || !Session.getActiveSession().isOpened()) {
                      String accessTokenString = sharedPreferences.getString("com.facebook.sdk.AccessToken", null);
                      Long accessTokenExpires = sharedPreferences.getLong("com.facebook.sdk.AccessTokenExpires", 0);
  
                      Session.setActiveSession(new Session.Builder(context).setApplicationId(context.getString(R.string.app_id)).build());
                      AccessToken accessToken = AccessToken.createFromExistingAccessToken(accessTokenString, new Date(accessTokenExpires), null, AccessTokenSource.FACEBOOK_APPLICATION_NATIVE, null);
                      Session.openActiveSessionWithAccessToken(context, accessToken, null);
                      // And then here I get the user's friends list and fail
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>This is the error I am getting every time I try:</p>
  
  <pre><code>Response:  responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 104, errorType: OAuthException, errorMessage: An access token is required to request this resource.}, isFromCache:false
  </code></pre>
  
  <p>I don't know what's the problem since I'm providing the access token and the access token expires that I'm getting from the user login, and when the user log in normally it works.</p>
  
  <p>Thanks in advance!</p>