2016-06-20 75 views
0

我想从Google云端硬盘下载文件到我的手机。到目前为止,我可以从我的应用访问Google云端硬盘,但到目前为止,我只能从Google云端硬盘中选择一个文件,但我无法下载它。从手机上的Google云端硬盘应用中,我可以做到这一点,但我需要从我的应用中执行此操作。如何从Google Drive下载文件到我的手机?

public void openFolder() { 

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() 
      + "/Android/data/com.google.android.apps.docs/files/"); 
    intent.setDataAndType(uri, "text/mp3"); 
    startActivity(Intent.createChooser(intent, "Open folder")); 

} 

通过此代码,我可以通过我的应用访问Google云端硬盘。 请帮忙吗?提前致谢。

回答

0

谷歌的指示说:

要下载的文件,你让授权的HTTP GET请求,该文件的资源URL和包括查询参数ALT =媒体。例如:

GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media 授权:承载ya29.AHESVbXTUv5mHMo3RYfmS1YJonjzzdTOFZwvyOAUVhrs

示例代码(在Java):

String fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M"; 
OutputStream outputStream = new ByteArrayOutputStream(); 
driveService.files().get(fileId) 
     .executeMediaAndDownloadTo(outputStream); 

你应该看看https://developer.android.com。此外,这里是从谷歌驱动器下载文件的具体信息页面:https://developers.google.com/drive/v3/web/manage-downloads#examples

相关问题