Google云端硬盘实施到Android应用并从Google云端

Google云端硬盘实施到Android应用并从Google云端

本文介绍了将Google云端硬盘实施到Android应用并从Google云端硬盘下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Drive快速入门应用程序示例仅适用于将文件从Android设备上传到用户帐户.我想将文件从Gdrive下载到android应用.任何帮助将不胜感激.

Drive Quick-start App example works for only uploading files from Android Device to user account. I want to download the files from Gdrive to android app. any help will be appreciated.

我想要此演示示例的完全相反的过程 https://developers.google.com/drive /quickstart-android (从Gdrive下载)

I want exact reverse process of this Demo example https://developers.google.com/drive/quickstart-android (download it from Gdrive)

推荐答案

有两个步骤可以从云端硬盘下载文件内容.首先,获取文件的元数据和文件的downloadUrl:

There are two steps to download file contents from Drive. First, retrieve the file's metadata and a downloadUrl for the file:

// retrieve metadata
File file = drive.files().get(fileId).execute();

然后,对downloadUrl进行身份验证的请求:

And, make an authenticated request to the downloadUrl:

// download contents a
GenericUrl url = new GenericUrl(file.getDownloadUrl());
HttpResponse response = drive.getRequestFactory().buildGetRequest(url).execute();
String contents = new Scanner(response.getContent()).useDelimiter("\\A").next();

这篇关于将Google云端硬盘实施到Android应用并从Google云端硬盘下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 07:43