AccountManagerFuture.getResult () leads to the "Login Failed" screen

I am trying to use AccountManager to get a token for an installed Google account. When I call getResult () on my AccountManagerFuture object, I get a β€œCannot log in” screen on the device (which further says: β€œAn error has occurred with Google servers. Please try again later.) I checked that a network connection is available before calling this method I also checked on a device that I can access, for example 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); 

In addition, these entries in LogCat may be useful:

 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: The actual gmail account name has been removed to avoid spam.)

+8
java android accountmanager
source share
1 answer

Are you creating a signed APK? If you do not create a signed APK (for example, if you just click "run application"), you will not be able to use the registered Google accounts on the device. Thus, you will have to click "log in with another" and log in the round-trip.

(Disclaimer: I did not try to run your code, but it sounds like a problem that I encountered before).

0
source share

All Articles