title: Gmail Imap authentication using AccountManager
body: <p>Using the code below I am able to get a token from the <code>AccountManager</code>. I am <strong>not</strong> able to figure out how to use this token with the javamail (IMAP) api for android (Session, Store, Folder,..) ?</p>
  
  <p>I would like to authenticate Gmail IMAP using the account manager, how should I go about doing this?</p>
  
  <pre><code>    AccountManager manager = AccountManager.get(this);
      Account[] accounts = manager.getAccounts();
  
      manager.getAuthToken(accounts[0], "oauth2:https://mail.google.com/", null, this, new AccountManagerCallback&lt;Bundle&gt;(){
  
          public void run(AccountManagerFuture&lt;Bundle&gt; future) {
              try {
                  String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
  
              } catch (OperationCanceledException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (AuthenticatorException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (MessagingException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
  
      }, null);
  </code></pre>