Search code examples
androidgoogle-sheetsgoogle-drive-android-api

Cannot create empty spreadsheet Drive API


I am using the sample code of googledrive and I am creating an empty file like:

MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
   .setMimeType(MIME_TYPE).build();

IntentSender intentSender = Drive.DriveApi.newCreateFileActivityBuilder()
   .setInitialMetadata(metadataChangeSet)
   .setInitialDriveContents(null /*or result.getDriveContents()*/) //both same results
   .build(getGoogleApiClient());

startIntentSenderForResult(intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);

For MIME_TYPE = "text/html" the code works as expected onActivityResult I get resultCode -> RESULT_OK intent with extras the DriveId of the created file. And if I browse my Google Drive I see the created file.

But when I change the MIME_TYPE = "application/vnd.google-apps.spreadsheet" in order to create an empty Spreadsheet then the resultCode -> RESULT_CANCELED with null intent and no file is created.

Do I need any extra parameter for the spreadsheet? Why it's not created?

Documentation mentions that the Spreadsheet API cannot create a file but you can use the Drive API for that.


Solution

  • At the moment you cannot create/edit Google Docs files with GDAA. To do this you will have to use the REST API.