I honestly see your example and it does not seem to work, in fact you need a Bitmap
to add through the dialog of Google Drive
This is a method which receives the bitmap of the image to be added to Google Drive:
//Create a new file and save it to Drive.
private void saveFileToDrive(Bitmap image) {
// Start by creating a new contents, and setting a callback.
Log.i(TAG, "saveFileToDrive() Creating new content.");
Drive.DriveApi.newDriveContents(mGoogleApiClient).setResultCallback(new ResultCallback<DriveContentsResult>() {
@Override
public void onResult(DriveContentsResult result) {
// If the operation wasn't successful, return
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "Failed to create new content!.");
return;
}
Log.i(TAG, "New content has been created.");
// Get an output stream for the contents.
OutputStream outputStream = result.getDriveContents().getOutputStream();
// Write the bitmap data from it.
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);
try {
outputStream.write(bitmapStream.toByteArray());
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}
// Create the initial metadata - MIME type and title.
// Note that the user will be able to change the title later.
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("image/jpeg").setTitle("myPhoto.png").build();
// Create an intent for the file chooser, and start it.
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(result.getDriveContents())
.build(mGoogleApiClient);
try {
startIntentSenderForResult(
intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
} catch (SendIntentException e) {
Log.i(TAG, "Failed to launch file chooser.");
}
}
});
}
Review this example that uses the camera to get the bitmap of the image to later upload to Google Drive.