【问题标题】:I try to download a google file, there isn't errors but it doesn't work我尝试下载一个谷歌文件,没有错误,但它不起作用
【发布时间】:2012-08-20 12:27:10
【问题描述】:

我正在使用谷歌驱动器开发一个应用程序,我可以使用这些应用程序查看我的文件。我想下载文件,但我不能。 这是我的功能,相当于google文档:

谢谢你!

  /* Download a file's content.
   * 
   * @param service Drive API service instance.
   * @param file Drive File instance.
   * 
   * @return InputStream containing the file's content if successful, {@code null} otherwise.
   */
 public static InputStream downloadFile(Drive service, File file) throws IOException
 {
    if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0)
     {
     try
     {
     HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
     return resp.getContent();
     }
     catch (IOException e)
     {
     // An error occurred.
     e.printStackTrace();
     return null;
     }
     }
    else
     {
     // The file doesn't have any content stored on Drive.
     return null;
     }
 }

Logcat 中没有错误,但我在下载、sd 卡等中没有看到任何文件

如果没有错误,我必须在sd卡,系统等中仔细查看?

这必然是别的什么??

【问题讨论】:

标签: android google-drive-api


【解决方案1】:

您正在获取文件内容并返回InputStream,但是您的代码没有显示您正在使用此InputStream 做什么。您需要使用它将文件内容保存到磁盘或数据库等...请查看FaddishWorm 在 cmets 中发送给您的将文件写入 SD 卡的链接:Download a file with Android, and showing the progress in a ProgressDialog

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    • 2020-09-07
    • 1970-01-01
    • 2023-01-08
    • 2021-03-29
    • 1970-01-01
    • 2022-11-22
    相关资源
    最近更新 更多