GetAuthToken does not call AccountManagerCallback

My code works as soon as the user authenticates my application to view and manage mail.

enter image description here

Or it looks something like this:

enter image description here

However, for the first time (for the first request), the Google dialog box appears at the top (above) and asks the user for authentication, then the AccountManagerCallback is never called, even if the user selects "OK" (even "Cancel" should return some value)

Here is my code:

AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, "oauth2:https://mail.google.com/", null, mActivity, new OnTokenAcquired(), null);

And the code of AccountManagerCallback:

private class OnTokenAcquired implements AccountManagerCallback<Bundle> {
        @Override
        public void run(AccountManagerFuture<Bundle> result) {
               // Do something useful
            }
        }
    }

Again, my code works (AccountManagerCallback calls) as soon as the user selects "OK" in the above dialog box. Then call the getAuthToken () method again.


Kitkat (Samsung Tab Pro 8.4), Bean (Galaxy Nexus). , Kitkat vs. Jelly Bean Samsung Nexus.

, ?

+4
1

KitKat . Google . - :

AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, "oauth2:https://mail.google.com/", null, false, new OnTokenAcquired(), null);

private class OnTokenAcquired implements AccountManagerCallback<Bundle> {

    @Override
    public void run(AccountManagerFuture<Bundle> result) {
           // Do something useful
            Bundle bundle;
            bundle = result.getResult();        

            Intent launch = (Intent)bundle.get(AccountManager.KEY_INTENT);
            if (launch != null) {                   
                launch.setFlags(0);
                mainActivity.startActivityForResult(launch, AUTHORIZATION_CODE);    
        }
    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (resultCode == RESULT_OK) {
        if (requestCode == AUTHORIZATION_CODE) {
            // request token here again 
    }
}
0

All Articles