Using the code below I am able to get a token from the AccountManager
. I am not able to figure out how to use this token with the javamail (IMAP) api for android (Session, Store, Folder,..) ?
I would like to authenticate Gmail IMAP using the account manager, how should I go about doing this?
AccountManager manager = AccountManager.get(this);
Account[] accounts = manager.getAccounts();
manager.getAuthToken(accounts[0], "oauth2:https://mail.google.com/", null, this, new AccountManagerCallback<Bundle>(){
public void run(AccountManagerFuture<Bundle> 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);