Created
September 16, 2020 06:32
-
-
Save tolunayozturk/557ea5e93b557b1260ae65bd1b59fc95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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