使用下面的代码,我可以从AccountManager
获取令牌。我不能够弄清楚如何在Android(会话,存储,文件夹,...)的javamail(IMAP)api中使用此令牌?
我想使用客户经理对Gmail IMAP进行身份验证,我应该怎么做呢?
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);