Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive Implementation to Android app and Downloading the file from Google drive

Drive Quick-start App example works for only uploading files from Android Device to user account. I want to download the files from Gdrive to android app. any help will be appreciated.

I want exact reverse process of this Demo example https://developers.google.com/drive/quickstart-android (download it from Gdrive)

like image 713
Backspace Avatar asked Apr 10 '13 09:04

Backspace


People also ask

How do I automatically download files from Google Drive?

Click Show advanced settings and go to Downloads. Click Change and in the pop-up, navigate to the Downloads folder you dragged to your Google Drive folder and click Select. This selection is now your default download location. Note: If Drive File Stream is not running, files are saved to a different location.

Why can't I download files from Google Drive Android?

If Google Drive won't download anything, the first step to fixing the issue is closing the browser and starting it again. Chrome browser is the most compatible with Google Drive, but it can also fail when you're trying to download from Google Drive. One of the best fixes is to clear cache from Chrome.


1 Answers

There are two steps to download file contents from Drive. First, retrieve the file's metadata and a downloadUrl for the file:

// retrieve metadata
File file = drive.files().get(fileId).execute();

And, make an authenticated request to the downloadUrl:

// download contents a
GenericUrl url = new GenericUrl(file.getDownloadUrl());
HttpResponse response = drive.getRequestFactory().buildGetRequest(url).execute();
String contents = new Scanner(response.getContent()).useDelimiter("\\A").next();
like image 107
Burcu Dogan Avatar answered Sep 21 '22 17:09

Burcu Dogan