![](/img/trans.png)
[英]Android - How to download the file from google drive to android SDCARD?
[英]How to download a file stored on Google Drive from an Android app?
我正在編寫一個Android應用程序,該應用程序啟動后需要從網上下載文件。
這是用於下載文件的方法。
private InputStream downloadUrl(String urlString) throws IOException { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("GET"); conn.setDoInput(true); conn.connect(); return conn.getInputStream(); }
我嘗試了以下方法,但並沒有取得太大的成功。
在Google驅動器上共享文件(在網絡上公開),然后使用給定的“共享URL”進行下載-出現錯誤-連接被拒絕
將文件發布到網絡上(通過Google雲端硬盤),並使用給定的“發布URL”進行下載-出現此錯誤-無法解析主機docs.google.com
是否可以為此目的使用Google驅動器?
提前致謝。
您想使用DriveApi.getFile和DriveFile.openContents在Google雲端硬盤中檢索文件。 據我所知,您不能直接通過url下載文件。
我正在使用這樣的代碼:
DriveFile file = Drive.DriveApi.getFile(client, driveId);
DriveApi.ContentsResult contentsResult = file.openContents(client, DriveFile.MODE_READ_ONLY, null).await();
if (!contentsResult.getStatus().isSuccess()) {
error = new Error("failed in retrieving the file content for " + driveId);
return null;
}
return getInputStream();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.