简体   繁体   English

从Android中的Google云端硬盘下载文件

[英]Download file from Google Drive in android

I followed this tutorial in my android app, and I can login, select, view file from my Google Drive account. 我在Android应用程序中遵循了教程,并且可以从Google云端硬盘帐户登录,选择和查看文件。 How can I download a file to my cache folder when I know the DriveId of the file. 知道文件的DriveId后,如何将文件下载到我的缓存文件夹中。 I know I can obtain drivefile like this. 我知道我可以这样获得驱动器文件。

DriveFile driveFile = mFileId.asDriveFile();

Can I convert this driveFile to File . 我可以将此driveFile转换为File I tried to cast it, didn't work. 我试图投射它,但是没有用。 In this link there is a method for downloading the file, but i can't find files() or executeMediaAndDownloadTo in my Drive driveService . 这个环节有下载的文件的方法,但在我的硬盘driveService我无法找到文件()executeMediaAndDownloadTo。 Is this for an old version? 这是旧版本吗? I couldn't find anything useful on the internet for this. 我在互联网上找不到任何有用的信息。

Try 尝试

DriveApi.DriveContentsResult result = id.asDriveFile()
                  .open(client, DriveFile.MODE_READ_ONLY, null).await();

check status is good with 检查状态好

result.getStatus().isSuccess()

then access the file with 然后使用

result.getDriveContents().getInputStream() 

client is your GoogleApiClient instance client是您的GoogleApiClient实例

Write the InputStream to a File if you want to create a copy of the file. InputStreamFile ,如果你想创建该文件的副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM