8

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.)

Smern
  • 18,746
  • 21
  • 72
  • 90
robguinness
  • 16,266
  • 14
  • 55
  • 65
  • 3
    Having the same problem. The scope (your variable authTokenType) is clearly related somehow. If I set it to "View your tasks" then the error goes away and I get a token. Unfortunately I'm not interested in viewing tasks. If I set it to https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile as suggested elsewhere, I get the error you're getting. Googling for some reference regarding the possible values for the scope has not worked for me yet, but I'm not giving up. – Adam Mackler Jan 04 '13 at 04:31
  • Hey, did you manage to solve your issue? I'm trying to implement the unofficial Google Music API into my android app and I'm running into the same "Couldn't sign in" screen. Thanks! – NewGradDev Sep 09 '13 at 20:32
  • I, for one, don't believe that I ever found a good solution. In my case, it wasn't critical, so I didn't invest a ton of time into it. @bee's answer though might point to the problem I was having because I wasn't generating a signed APK. – robguinness Sep 11 '13 at 10:17
  • This question: http://stackoverflow.com/questions/14365219/in-a-nutshell-whats-the-difference-from-using-oauth2-request-getauthtoken-and-g/ says it's harder than that, and looks like one needs `GoogleAuthUtil`. – Victor Sergienko Sep 19 '13 at 16:51

1 Answers1

0

Are you generating a signed APK? If you don't generate a signed APK (e.g., if you just hit "run app") you won't be able to take advantage of registered Google accounts on the device. So you'll have to hit "login with other" and login the roundabout way.

(Disclaimer: I didn't try to run your code, but it sounds like an issue I ran into earlier.)

bee
  • 216
  • 1
  • 13