Not the first day I am at war with this problem.
This code downloads images on the drive.
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 am trying to get the id of the uploaded file.
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 as you can see from the logs, the id I get is not full
07-06 15:15:50.939 19899-19899/valery.pankov.gdriveapp D/Fileidis: DriveId:CAESABj4XSCG9Oqbt1EoAA==
I tried on UploadFileOnGoogleDrive
install idResultCallback
, but this was not a success.