Create a file and query file with custom property work fine, but it cannot retrieve custom property in queryChildren() ResultCallback.
Here is the CustomProperty definition:
/**
* CustomPropertyKey: Uploaded file's hash code
*/
public static final CustomPropertyKey CustomPropertyKeyFileHash =
new CustomPropertyKey("fileHash", CustomPropertyKey.PUBLIC);
query conditions:
Query query = new Query.Builder()
.addFilter(
Filters.and(
Filters.eq(SearchableField.MIME_TYPE, sMimeType),
Filters.eq(BaseDemoActivity.CustomPropertyKeyFileHash, mDriveFile.getMD5()),
Filters.eq(SearchableField.TRASHED, false)
)
).build();
mDriveFile.getDriveFolder().queryChildren(mGoogleApiClient, query)
.setResultCallback(mResultCallback);
query result callback:
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Problem while retrieving results");
return;
}
MetadataBuffer mdb = result.getMetadataBuffer();
if (mdb.getCount() > 0) {
try {
if (mdb != null) {
for (Metadata md : mdb) {
if (md == null) continue;
Log.d(TAG, "[FileMetadataCallback][onResult] md.getTitle(): " + md.getTitle() + ", md.getDriveId(): " + md.getDriveId());
Log.d(TAG, "[FileMetadataCallback][onResult] md.getTitle(): " + md.getTitle() + ", md.getResourceId(): " + md.getDriveId().getResourceId());
Map<CustomPropertyKey, String> map = md.getCustomProperties();
if (map != null) {
Log.d(TAG, "[FileMetadataCallback][onResult] file custom properties size: " + map.size());
if (map.size() > 0) {
Log.d(TAG, "[FileMetadataCallback][onResult] file hash: " + map.get(CustomPropertyKeyFileHash));
}
}
}
}
} finally {
if (mdb != null) mdb.close();
}
}
}
I always get log "[FileMetadataCallback][onResult] file custom properties size: 0". However, I should able to retrieve "mDriveFile.getMD5()" since it is one of query conditions, right?
Any suggestion is appreciated.
Just found that it needs to wait a moment (some minutes) to get custom property properly after onCompletion callback. So this should be none issue if you don't need to get custom property immediately after onCompletion callback.