Aram
Aram

Reputation: 695

Get image thumbnail from google drive in Android

Is it possible to get image thumbnail from google drive image file ? When I'm opening the native google drive app, it shows me thumbnails of images, but when I'm opening the file chooser of API, it's shows me default icon for all images.

Upvotes: 0

Views: 2502

Answers (3)

creativedrewy
creativedrewy

Reputation: 101

Update: I had an error in the discussion of the request fields.

As far as I can tell, there is literally no good documentation on the solution for this. It's true that you can't get thumbnails with the Drive Android API, however you can get thumbnails with the Drive Java Client Library. This page has is a really good primer for getting started:

https://developers.google.com/drive/v3/web/quickstart/android

Oddly, I can't get the fields portion of the request to work as it is on that quick start. As I've experienced, you have to request the fields a little differently.

Since you're doing a custom field request you have to be sure to add the other fields you want as well. Here is how I've gotten it to work:

Drive.Files.List request = mService.files()
                    .list()
                    .setFields("files/thumbnailLink, files/name, files/mimeType, files/id")
                    .setQ("Your file param and/or mime query");

FileList files = request.execute();
files.getFiles();  //Each File in the collection will have a valid thumbnailLink

A sample query might be:

"mimeType = 'image/jpeg' or mimeType = 'video/mp4'"

Hope this helps!

Upvotes: 0

Burcu Dogan
Burcu Dogan

Reputation: 9213

Google Drive Android API doesn't provide thumbnails at the moment, they will be likely to be available on the new version.

Upvotes: 1

gatlingxyz
gatlingxyz

Reputation: 753

It's very simple, actually.

On the file (com.google.api.services.drive.model.File) you get back, just call getThumbnailLink(). That will be the thumbnail of the image. However, if it's not an image, if I remember correctly, it will simply be blank (not null, but just blank).

Upvotes: 0

Related Questions