Mik*_*ine 6 android google-drive-api android-download-manager
我正在尝试使用 android DownloadManager 下载存储在 Google Drive 中的文件。
我从 Google 获得登录令牌,如下所示:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(AppConfig.getInstance().get("google_client_id"))
.requestProfile()
.requestEmail()
.build();
Run Code Online (Sandbox Code Playgroud)
我收到一个带有谷歌驱动器文件 url 的通知,我将它传递给 DownloadManager,将令牌传递给它:
String cookie = CookieManager.getInstance().getCookie(d.getURL());
request.addRequestHeader("Cookie",cookie);
request.addRequestHeader("Authorization", "OAuth " + profile.getToken());
//d is the document object, that contains url, file name, etcc
//Profile is a simple object class that hold the user data taken from sign Google, like token, name, email, etcc
Run Code Online (Sandbox Code Playgroud)
使用简单的广播接收器来管理下载结果 (ACTION_DOWNLOAD_COMPLETE)。
下载已成功完成,但文件已损坏。如果我尝试打开它,设备(和电脑)会给我一个格式错误。该文件包含 Google 页面的 HTML 代码,该代码表示存在错误,仅此而已。
(我正在使用的帐户可以从这个特定的驱动器存储中读取和下载文档)
这是使用 DownloadManager 下载 Google Drive 文件的正确方法吗?有可能这样做吗?
您还可以通过此方法从谷歌下载文件
参考这个网址
https://drive.google.com/uc?id=<FILE_ID>&export=download
Run Code Online (Sandbox Code Playgroud)
替换<FILE_ID>为您的可共享文件 ID。
此外,您可以从此解决方案获取帮助下载 Android 文件,并在 ProgressDialog 中显示进度
您可以使用其中的 doInBackground 函数来解决您的查询。
| 归档时间: |
|
| 查看次数: |
921 次 |
| 最近记录: |