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();
}
};