1

I am working on an android app, which should be able to read a spreadsheet from google drive. However, every time when I try to open a file from google drive I get following message from the DriveContentsResult: "No content is available for this file".

Here is my code, after I got the authorization for google drive via the GoogleApiClient:

private static final int REQUEST_RESOLVE_ERROR = 1001;
public static final int REQUEST_CODE_OPENER = 1002;
private DriveId mSelectedFileDriveId;
public GoogleApiClient mGoogleApiClient;

public void getGoogleDriveFile(View view){
    if(mGoogleApiClient.isConnected()){
        IntentSender intentSender = Drive.DriveApi
                .newOpenFileActivityBuilder()
                .setMimeType(new String[] {"application/vnd.google-apps.spreadsheet"})
                .build(mGoogleApiClient);

        try {
            startIntentSenderForResult(intentSender, REQUEST_CODE_OPENER, null, 0, 0, 0);
        } catch (SendIntentException e) {
            Log.d(TAG, "Unable to send intent" + e);
        }
    } 
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult");
    if (requestCode == REQUEST_RESOLVE_ERROR) {
     ...
    } else if(requestCode == REQUEST_CODE_OPENER){
        if(resultCode == RESULT_OK){
            mSelectedFileDriveId = (DriveId) data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);                          
            if(mSelectedFileDriveId != null){
                open();
            }  
        } 
    }
}
private void open() {
     Drive.DriveApi.getFile(mGoogleApiClient, mSelectedFileDriveId)
     .open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null)
     .setResultCallback(driveContentsCallback);
}
private ResultCallback<DriveContentsResult> driveContentsCallback =
     new ResultCallback<DriveContentsResult>() {
     @Override
     public void onResult(DriveContentsResult result) {
         if (!result.getStatus().isSuccess()) {
             Log.d(TAG, "Error while opening the file contents " + result.getStatus().getStatusMessage());
             return;
         }
            DriveContents contents = result.getDriveContents();
        }
};
mklaus
  • 11
  • 2
  • Try adding the tag google-drive-android-api which might pick up the attention of more appropriate Google engineers: http://developers.google.com/drive/support – plinehan Jan 28 '15 at 17:59

2 Answers2

1

Content here refers to binary content. Google Spreadsheets (and the other Google Docs types) are not stored as binary content. The Android-specific API doesn't currently support reading Spreadsheet contents.

Using the RESTful API, you can get it in a binary format like csv using the ExportLinks.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • See also: http://stackoverflow.com/questions/27728614/i-am-unable-to-download-contents-of-a-file-using-google-drive/28199160#28199160 – plinehan Jan 28 '15 at 18:01
  • Long story short, the Android API simply doesn't support Docs content. – plinehan Jan 28 '15 at 18:01
0

use the "google spreadsheets api" (REST) not drive api.

Zig Mandel
  • 19,571
  • 5
  • 26
  • 36