Gmail Imap authentication using AccountManager
Asked Answered
H

1

6

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);
Hermia answered 28/12, 2011 at 7:39 Comment(1)
Did you find any solution to this? I am also looking for same..Astilbe
H
-1

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

Hornpipe answered 22/5, 2013 at 18:2 Comment(2)
You've linked to a generic Java library which doesn't use the Android AccountManager at all.Squeaky
The original post wasn't about how to use the AccountManager, it was about how the AccountManager token was to be used in the javamail (IMAP) api. The code samples provided clearly showed examples for how to accomplish this task and worked for me which is why I provided it. At this point I would recommend that the original question be downvoted or closed as there are much more comprehensive examples and discussions scattered throughout SO.Hornpipe

© 2022 - 2024 — McMap. All rights reserved.