I have spend more then one day but not getting any working solution which provide me uploading / downloading files to Google Drive
.
I have tried Google Play Service
but i didn't find any method which upload / download files.
I try Google Client libraries but there are some method are not resolved.
such as :
service.files().insert(body, mediaContent).execute();
errors: The method execute() is undefined for the type Drive.Files.Insert
I can upload image through below code but this is Google Drive file up loader. I can only upload one only one file at a time.
mFile = new java.io.File(fileList.get(i));
Log.i(TAG, "Creating new contents.");
Drive.DriveApi.newContents(mGoogleApiClient).addResultCallback(
new OnNewContentsCallback() {
@Override
public void onNewContents(ContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.i(TAG, "Failed to create new contents.");
return;
}
Log.i(TAG, "New contents created.");
OutputStream outputStream = result
.getContents().getOutputStream();
byte[] byteStream = new byte[(int) mFile
.length()];
try {
outputStream.write(byteStream);
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("image/jpeg")
.setMimeType("text/html")
.setTitle("Android Photo.png").build();
// Create an intent for the file chooser, and
// start it.
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialContents(
result.getContents())
.build(mGoogleApiClient);
try {
mActivity.startIntentSenderForResult(
intentSender, REQUEST_CODE_CREATOR,
null, 0, 0, 0);
publishProgress(1);
} catch (SendIntentException e) {
Log.i(TAG, "Failed to launch file chooser.");
publishProgress(0);
}
}
});
But still fighting for downloading a file.