title: Never get AccountManager.KEY_INTENT from getAuthToken request
body: <p>On JellyBean device.</p>
  
  <p>I'm following <a href="http://developer.android.com/training/id-auth/authenticate.html" rel="nofollow">this</a> to request an oauth2 token, e.g.</p>
  
  <pre><code>AccountManager am = AccountManager.get(getActivity());
  am.invalidateAuthToken(MY_AUTH_TOKEN_TYPE, null);
  am.getAuthToken(aGoogleAccount, MY_AUTH_TOKEN_TYPE, null, this, 
      new OnTokenAcquired(), new Handler(new OnError()));
  </code></pre>
  
  <p>and then make the check as per the later code sample:</p>
  
  <pre><code>private class OnTokenAcquired implements AccountManagerCallback&lt;Bundle&gt; {
  @Override
      public void run(AccountManagerFuture&lt;Bundle&gt; result) {
          Bundle bundle = result.getResult();
          ...
          Intent launch = (Intent) bundle.get(AccountManager.KEY_INTENT);
          if (launch != null) {
              startActivityForResult(launch, 0);
              return;
          }
      }
  }
  </code></pre>
  
  <p>I never get a KEY_INTENT. I understand the following:</p>
  
  <blockquote>
    <p>There may be many reasons for the authenticator to return an Intent. It may be the first time the user has logged in to this account. Perhaps the user's account has expired and they need to log in again, or perhaps their stored credentials are incorrect. Maybe the account requires two-factor authentication or it needs to activate the camera to do a retina scan. It doesn't really matter what the reason is. If you want a valid token, you're going to have to fire off the Intent to get it.</p>
  </blockquote>
  
  <p>However, the <code>getAuthToken</code> always results in the permission screen, or login screen, appearing before the code hits the <code>run</code> method at which point the token is valid. I've tried:</p>
  
  <ol>
  <li>Turning on 2 step authentication. Account login is requested before <code>run</code> so always have the token in <code>run</code>.</li>
  <li>Changing the password on the server. Again account login is requested before <code>run</code> so always have the token in <code>run</code>.</li>
  </ol>
  
  <p>Don't have the ability to try a retina scan so somewhat at a loss.</p>
  
  <p><strong>EDIT 1</strong> The problem I have is that there may be a circumstance where I will get a <code>KEY_INTENT</code> and so I'd rather test this code path now rather when when it's out in the field.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Peter.</p>