Google Drive Android Api Completion Event for Folder Creation

那年仲夏 提交于 2019-12-02 04:47:38
seanpj

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.

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