2

I'm developing an app with google drive and I can see my files with these app. I want to download the files, but I can't. This is my function, is equal to google documentation:

Thanks un advance!!

  /* 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;
     }
 }

No errors in Logcat, but I don't see any file in downloads, sd-card, etc

If there isn't error, I have to see very carefull in sd-card, system etc?

it's necessarely anything else??

Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
  • 1
    Check out this guide: http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog It shouldn't matter that it is google drive, because you are using a URL anyway :) – ddoor Aug 20 '12 at 12:31

1 Answers1

1

You are getting the file content and returning an InputStream however your code doesn't show what you are doing with this InputStream. You need to use it to save the content of the file to Disk or database etc... Please have a look at the link that FaddishWorm sent you in comments which writes the file to the SD Card: Download a file with Android, and showing the progress in a ProgressDialog

Community
  • 1
  • 1
Nicolas Garnier
  • 12,134
  • 2
  • 42
  • 39