I'm trying to solve this problem for a long time. This part of code download image to GDrive.
public void UploadFileOnGoogleDrive(DriveContentsResult result){
final DriveContents driveContents=result.getDriveContents();
new Thread(){
@Override
public void run(){
OutputStream outputStream = driveContents.getOutputStream();
// Write the bitmap data from it.
String photo = "IMG23.jpg";
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),photo);
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
int numOfbytes = myBitmap.getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(numOfbytes);
myBitmap.copyPixelsToBuffer(buffer);
//imageInByte = buffer.array();
myBitmap.compress(Bitmap.CompressFormat.JPEG, 80, bitmapStream);
try {
outputStream.write(bitmapStream.toByteArray());
//outputStream.write(bitmapStream.toByteArray());
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("image/jpeg")
.setTitle(photo)
.setIndexableText(photo)
.build();
Log.d("Description",metadataChangeSet.getIndexableText());
Drive.DriveApi.getRootFolder(mGoogleApiClient)
.createFile(mGoogleApiClient, metadataChangeSet, driveContents).
setResultCallback(fileCallback);
//Drive.DriveApi.fetchDriveId(mGoogleApiClient,EXISTING_FILE_ID).setResultCallback(idfileCallback);
}
}.start();
}
Here I try to get file ID
final private ResultCallback<DriveFolder.DriveFileResult> fileCallback = new
ResultCallback<DriveFolder.DriveFileResult>() {
@Override
public void onResult(DriveFolder.DriveFileResult result) {
if (result.getStatus().isSuccess()) {
Toast.makeText(getApplicationContext(), "file created: "+""+
result.getDriveFile().getDriveId(), Toast.LENGTH_LONG).show();
//DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient, result.getDriveFile().getDriveId());
//file.getMetadata(mGoogleApiClient)
// .setResultCallback(metadataRetrievedCallback);
//String id=file.getDriveId().encodeToString();
Log.d("Fileidis",result.getDriveFile().getDriveId().encodeToString());
//final DriveId fileid = result.getDriveFile().getDriveId();
//DriveFile driveFile=Drive.DriveApi.getFile(mGoogleApiClient,fileid);
}
return;
}
};
But we find not fully ID in logs
07-06 15:15:50.939 19899-19899/valery.pankov.gdriveapp D/Fileidis: DriveId:CAESABj4XSCG9Oqbt1EoAA==
I thought set idResultCallback
on UploadFileOnGoogleDrive
but it was not successfull.
Thanks in advance