balee
balee

Reputation: 173

How to set Google Drive access timeout on Android

Let's list files from Google Drive:

GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(
    context, DriveScopes.DRIVE);
Drive service = new Drive.Builder(AndroidHttp.newCompatibleTransport(), 
    new GsonFactory(), credential).build();
service.files().list().execute();

However, execute() takes almost forever to realize if for example there is no network connection available.

It turns out from the source of GoogleAccountCredential that it uses ExponentialBackOffPolicy, which has a 15 minutes maximum elapsed time limit by default.

Question 1: Is there a way to override this behavior and set the timeout limit to a lower value?

Question 2: service.files().list().execute() is running in an AsyncTask. What is the correct way to cancel it on user request, if she doesn't want to wait for that 15 mins timeout?

Upvotes: 1

Views: 1118

Answers (1)

Yaniv Inbar
Yaniv Inbar

Reputation: 1499

Thanks for the feedback!

Doesn't look like there is any way to customize the exponential backoff policy on GoogleAccountCredential. I filed a feature request here:

https://code.google.com/p/google-api-java-client/issues/detail?id=734

It doesn't look like there's a good way to cancel either. Feature request filed here:

https://code.google.com/p/google-api-java-client/issues/detail?id=735

NOTE: I'm an owner on the google-api-java-client project

Upvotes: 3

Related Questions