I am currently developing an Android application that utilizes the Google Drive API. While I managed to implement most features, I’m having trouble figuring out how to retrieve the specific file ID necessary for downloading.
So far, I’ve been able to list all files available in my Drive and have stored them in an array list. I tested the download by using the ID of the first file in that list. When I input this ID directly into my download function, it works without any problems.
However, I am unsure how to obtain the ID for a particular file that I want to download. I have included my current implementation below:
private void downloadFileRegion() {
Thread myThread = new Thread(new Runnable() {
@Override
public void run() {
try {
com.google.api.services.drive.model.File fileDetails = service.files().get("0B-Iak7O9SfIpYk9zTjZvY2xreVU").execute();
if (fileDetails.getDownloadUrl() != null && fileDetails.getDownloadUrl().length() > 0) {
HttpResponse httpResponse = service.getRequestFactory().buildGetRequest(new GenericUrl(fileDetails.getDownloadUrl())).execute();
InputStream myInputStream = httpResponse.getContent();
saveToFile(myInputStream);
}
} catch (IOException e) {
Log.e("DownloadError", e.toString());
e.printStackTrace();
}
}
});
myThread.start();
}
The ID that I used, 0B-Iak7O9SfIpYk9zTjZvY2xreVU
, worked for testing but I need to be able to dynamically retrieve the ID for a specific file named ‘File_1’ that I want to download.
Ultimately, my goal is to upload an XML file to Google Drive with my app and later be able to download that exact file. It’s always going to be the same file name, so I would like to know if there’s a more effective way to achieve this.