3

I want get the resourceId after upload but it's returning null. Can you help me to get this value?
Thanks in advance.

Drive.DriveApi.getFolder(getGoogleApiClient(), driveIdResult.getDriveId())
    .createFile(getGoogleApiClient(), changeSet, driveContents)
    .setResultCallback(new ResultCallbacks<DriveFolder.DriveFileResult>() {
        @Override
        public void onSuccess(@NonNull final DriveFolder.DriveFileResult driveFileResult) {
            if (driveFileResult.getStatus().isSuccess()) {
                String driveId = driveFileResult.getDriveFile().getDriveId().toString();
                //return this:
                //DriveId:CAESHDBCeEc0ZnI0YkQ0ZVZRa1E1YTNVMFVtUTRkRlUY1GcgsPT0w7xTKAA=

                String resourceId = driveFileResult.getDriveFile().getDriveId().getResourceId();
                //null
                //but I want something like this: 0BxG4fr4bD4eVQXRjbTRBV2RMUHc
                uploadCallBack.onFinish(true, resourceId);
            }
        }

        @Override
        public void onFailure(@NonNull com.google.android.gms.common.api.Status status) {
            uploadCallBack.onFinish(false, null);
        }
});
Daniele Ricci
  • 571
  • 1
  • 7
  • 28
ialfa1987
  • 83
  • 7

1 Answers1

1

I think you can follow this user's suggestion: https://stackoverflow.com/a/31553269/1045199

Judging from your code, DriveId.toString() returns something useful you can use to compare it to the event. I'd say:

  • create a map of <String, UploadCallback>, using DriveId.toString as keys
  • setup and register a DriveEventService with onCompletion()
  • inside the upload result callback, call file.addChangeSubscription(getGoogleApiClient()) so that you will get notifications in your DriveEventService
  • from inside onCompletion() you can get a DriveId to use for Map.get() by invoking event.getDriveId()

I didn't test it, but it should work, at least in theory.


EDIT: https://stackoverflow.com/a/25555159/1045199 describes a very similar approach. Remember to call setNotifyOnCompletion(true) when you build your ExecutionOptions.

Community
  • 1
  • 1
Daniele Ricci
  • 571
  • 1
  • 7
  • 28