I am attempting to use AccountManager to get a token for an installed Google account. When I call getResult() on my AccountManagerFuture object, I get the "Couldn't sign in" screen on the device (which further says, "There was a probem communicating with Google servers. Try again later.). I checked that a network connection is available prior to calling this method. I also checked on the device that I am able to access, e.g. google.com, in the browser. Here is the code for my AccountManagerCallback:
amf = accMgr.getAuthToken(account, authTokenType, null, true,
new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> arg0) {
Bundle result;
Intent i;
String token;
try {
result = arg0.getResult();
if (result.containsKey(AccountManager.KEY_INTENT)) {
i = (Intent)result.get(AccountManager.KEY_INTENT);
if (i.toString().contains("GrantCredentialsPermissionActivity")) {
// Will have to wait for the user to accept
// the request therefore this will have to
// run in a foreground application
cbt.startActivity(i);
} else {
cbt.startActivity(i);
}
token = (String)result.get(AccountManager.KEY_AUTHTOKEN);
} else {
token = (String)result.get(AccountManager.KEY_AUTHTOKEN);
}
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}, handler);
Also, these entries in LogCat might be helpful:
08-02 15:51:00.911: I/GLSUser(10134): GLS error: Unknown XXXX@gmail.com com.google
08-02 15:51:00.911: V/GoogleLoginService(10134): Returning error intent with: ComponentInfo{com.google.android.gsf.login/com.google.android.gsf.login.LoginActivity}
08-02 15:51:03.294: I/ActivityManager(324): START {cat=[XXXX@gmail.com] flg=0x10000000 cmp=com.google.android.gsf.login/.LoginActivity (has extras) u=0} from pid 11147
(Note: Actual gmail account name removed to avoid spam.)