我使用Google Drive API查询文件并检索其元数据。在之前从未安装的设备上运行应用程序时,返回的MetadataBuffer为空(正如我从logcat中看到的那样)。 如果我卸载应用程序并重新安装它,相同的代码会生成带有预期元数据对象的MetaDataBuffer。这种情况发生在我测试过的每一台设备上。我假设它与本地缓存有关。我想知道我的代码中是否遗漏了某些内容,或者我最终应该向Google提出问题 这是完整的代码:
public void setupClient(boolean noProgress) {
Log.i("drive", "setup client...");
mGoogleApiClient = new GoogleApiClient.Builder(parent)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(connectionCallbacks)
.addOnConnectionFailedListener(connectionFailedListener)
.build();
mGoogleApiClient.connect();
}
private GoogleApiClient.ConnectionCallbacks connectionCallbacks = new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
Log.i("drive", "connected");
Filter mime = Filters.eq(SearchableField.MIME_TYPE, MIME_TYPE);
Filter trashed = Filters.eq(SearchableField.TRASHED, false);
Query query = new Query.Builder()
.addFilter(mime)
.addFilter(trashed)
.build();
Drive.DriveApi.query(mGoogleApiClient,query).setResultCallback(metadataCallback);
}
private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback = new
ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult metadataBufferResult) {
MetadataBuffer buffer = metadataBufferResult.getMetadataBuffer();
Log.i("drive", String.valueOf(buffer.getCount()));
if (buffer.getCount()>0) {
/* this is where it fails:
the first time, getCount() is 0. the following times,
getCount() is the right number of files in the Drive */
Log.i("drive","files found");
//do things with metadata...
} else {
Log.i("drive","files not found");
//do other things when there are no files...
}
}
};
答案 0 :(得分:0)
本地同步需要一些处理。如果您在完成之前提出请求,则可能会得到不完整的结果。您可以使用requestSync等待同步完成。 (尽管如果已经有正在进行的请求,有时此请求会受到速率限制。我们正在努力改善此行为。)