2016-06-20 392 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

相關問題