Gmail Imap Authentication with AccountManager

Using the following code, I can get the token from AccountManager . I can not understand how to use this token with javamail (IMAP) api for Android (session, store, folder, ..)?

I would like to authenticate Gmail IMAP using Account Manager, how do I do 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); 
+6
source share
1 answer

See google-mail-oauth2-tools
Once you have the token, you can use these code samples to complete the rest.

-1
source

Source: https://habr.com/ru/post/904583/


All Articles