1

The completion events in Google Drive Android Api (GDAA) seem to be invoked only by contents change (file create, file contents update). Since I need to retrieve a Resource Id of a folder (seen here for a file with contents), referring to this method:

   DriveFolder.createFolder(mGAC, meta).setResultCallback(...);

I need a completion event for a folder creation, but I can't find a solution.

Any hints? Thank you.

Community
  • 1
  • 1
seanpj
  • 6,735
  • 2
  • 33
  • 54
  • I think completion events only work with `DriveFile` and not `DriveFolder`. Would getting the [`ResultCallback`](https://developers.google.com/android/reference/com/google/android/gms/common/api/ResultCallback) of `DriveFolderResult` suffice after you've created the folder suffice? After creating the folder, you should be able to check if it was successful or not (see [onResult](https://developers.google.com/drive/android/folders#create_a_folder_in_the_root_folder)). – Andy Dec 17 '15 at 22:16
  • No, you get the 'preliminary' DriveId (see [here](http://stackoverflow.com/questions/22874657/unpredictable-result-of-driveid-getresourceid-in-google-drive-android-api/31553269#31553269) ), that yields ResourceId of null. That means you're getting a DriveId created by local GooPlaySvcs before it is commited (uploaded). I'm working on a hack and will post result if nobody else takes a bait. – seanpj Dec 17 '15 at 22:22

1 Answers1

3

No, takers for this question, so I assume there is no straightforward solution. Meanwhile, I slammed together a hack until this gets fixed (if ever).

1/ Create a folder, you get the 'preliminary' DriveId that YIELDS NO ResourceId (nothing's commited).

2/ Use this DriveId as a parent of a dummy file with a dummy content and a completion event request attached. The folder creation is now apparently forced by it's child.

3/ In the completion event (as seen here), get the dummy file's DriveId and retrieve it's parent ID:

  com.google.android.gms.common.api.GoogleApiClient GAC;   
  //...   
  DriveId parentID(DriveId dId) {
    MetadataBuffer mdb = null;
    DriveApi.MetadataBufferResult mbRslt = dId.asDriveResource().listParents(GAC).await();
    if (mbRslt.getStatus().isSuccess()) try {
      mdb = mbRslt.getMetadataBuffer();
      if (mdb.getCount() > 0)
        return mdb.get(0).getDriveId();
    } catch (Exception e) { e.printStackTrace();}
    finally {
      if (mdb != null) mdb.close();
    }
    return null;   
  }

('await()' flavor works here since 'DriveEventService' is off-UI)

Now you get folder's 'real' DriveId that can produce a valid ResourceId:

String resourceId = driveId.getResourceId()

4/ zap the dummy file that has served it's lifetime mission

Is there a better solution? Please let me know.

Community
  • 1
  • 1
seanpj
  • 6,735
  • 2
  • 33
  • 54
  • I have came across the same situatuion, have you found a better soultion? if not, can you please explain how can you access the data from inside the completion event? for example the GAC? how is it accessible? you need a context\activity in order to create it – Daniel Katzan Apr 29 '16 at 15:55
  • @DanielKatzan Sorry I have retired half a year ago and am not active in this anymore I may get back to it sometime in the future (when Google finally stabilizes if - or kills it :-) – seanpj Apr 30 '16 at 12:48