Skip to content

Instantly share code, notes, and snippets.

@tolunayozturk
Created September 16, 2020 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tolunayozturk/557ea5e93b557b1260ae65bd1b59fc95 to your computer and use it in GitHub Desktop.
Save tolunayozturk/557ea5e93b557b1260ae65bd1b59fc95 to your computer and use it in GitHub Desktop.
private void downloadFiles() {
new Thread(new Runnable() {
@Override
public void run() {
try {
if (mAccessToken == null) {
Log.d(TAG, "need to sign in first");
return;
}
if (fileSearched == null) {
Log.d(TAG, "query file first");
return;
}
Drive drive = buildDrive();
File fileToDownload = new File();
Drive.Files.Get request = drive.files().get(fileSearched.getId());
fileToDownload.setFileName(fileSearched.getFileName())
.setId(fileSearched.getId());
MediaHttpDownloader downloader = request.getMediaHttpDownloader();
downloader.setContentRange(0, fileSearched.getSize() - 1);
String path = getExternalFilesDir(null).getAbsolutePath() + "/" + fileSearched.getFileName();
request.executeContentAndDownloadTo(new FileOutputStream(new java.io.File(path)));
Log.d(TAG, "download success");
} catch (Exception e) {
Log.d(TAG, "download error " + e.toString());
}
}
}).start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment