Question

here's yet another pit a fell into when trying to implement the new Google Drive Android API (GDAA):
Activity A of my app needs functionality not supported by GDAA, so I resort to using the original Google Drive SDK v2 per the statement here.:

In some cases, applications may need to use the Google Drive web service to access additional features or access broader scopes than what is available in the Google Drive Android API. In these cases, your application must use the Google APIs Client Library for Java.

The auth sequence is standard:

...
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE);
credential.setSelectedAccountName(accountName);
...

The authentication / authorization with DRIVE_FILE scope is succesful.

In Activity B, I use the GDAA, going through the standard sequence

  1. x = new GoogleApiClient.Builder(this)....build();
  2. x.connect()
  3. onConnectionFailed()
  4. startResolutionForResult()

and this is where the problem appears. The user already went through account selection and authorization in Activity A, but GDAA does not know anything about it. This causes a new account selection dialog to pop up again. So the question is:
Is there a way to pass the initialized credentials to GDAA without bugging the user again (scope's the same)?
If the app needs to use both Google Drive SDK v2 and GDAA (as will probably be the case for any, but most trivial app), showing the account selection dialog more than once will certainly be a showstopper.

Was it helpful?

Solution

When building a new GoogleApiClient, you can explicitly set an account name.

x = new GoogleApiClient.Builder(this)
       .addScope(Drive.SCOPE_FILE)
       .setAccountName(accountName)...

Since the application is authorized for the account, it will automatically connect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top