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.
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