John Roberts
John Roberts

Reputation: 5966

Creating New Google Drive Document From Android

I am trying to add the functionality to create a new Google Drive document (presentation, spreadsheet, etc.) to my app. To do this, I initially wanted to just use URL intents, but it seems that one cannot create a new Google Drive document through the Android browser. My next idea is to somehow integrate with the Google Drive app. Is there anyway to call/open the Google Drive app from my app (for example, with intents)?

Upvotes: 3

Views: 706

Answers (2)

smokybob
smokybob

Reputation: 662

As stated by Claudio, the change is minimal when you take a deep look at the API JavaDoc.

Instead of using

File insertedFile = service.files().insert(newFile, content).execute();

Use this:

Insert fileRequest = service.files().insert(newFile, content);
fileRequest.setConvert(true);
File insertedFile = fileRequest.execute();

The conversion table can be found here:

https://developers.google.com/drive/integrate-open?hl=en

Had and hard time finding this info but now it's all clear.

Upvotes: 1

Claudio Cherubino
Claudio Cherubino

Reputation: 15004

You can use the Google Drive API to upload a file to Drive and have it automatically converted to the corresponding Google format. For instance, you can upload a text file and have it converted to a Google Docs.

The Android quickstart for Drive shows how to upload a photo, it should be easy to change the code to upload a different file instead and add the ?convert=true parameter:

https://developers.google.com/drive/v2/reference/files/insert

Upvotes: 1

Related Questions