How do I switch accounts under the NEW Google Drive Android API
android, google-drive-android-api, google-drive-api
Solution
Just call
`mGoogleApiClient.clearDefaultAccountAndReconnect();`
have a look at the docs.
This will call the `onConnectionFailed` callback that will present the layout to choose among the available Google accounts:
@Override
public void onConnectionFailed(ConnectionResult connectionResult)
{
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, message user appropriately
}
} else {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
}
}
Problem
My authorization flow in the new Google Drive Android API is as follows: - Menu: SELECT ACCOUNT - connect(); - onConnectionFailed() result.startResolutionForResult() invokes AccountSelectDialog / DriveAuthorization - onConnected() do your stuff Works like a charm. Now repeating with the aim to switch accounts: - Menu: SELECT ACCOUNT - connect(); - onConnected() Here, I have no chance to get to the AccountSelectDialog since I never get onConnectionFailed() with 'result' to invoke startResolutionForResult(). What am I missing this time?