Google Drive Android Api Completion Event for Folder Creation

后端 未结 1 375
耶瑟儿~
耶瑟儿~ 2021-01-24 18:17

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 o

相关标签:
1条回答
  • 2021-01-24 18:44

    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.

    0 讨论(0)
提交回复
热议问题