Google Drive Android Api Completion Event for Folder Creation

人盡茶涼 提交于 2019-12-02 08:17:48

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/34318220/google-drive-android-api-completion-event-for-folder-creation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!