Google 드라이브 API를 사용하여 파일을 쿼리하고 메타 데이터를 검색합니다. 에서 앱을 실행하는 경우 전에 설치하지 않은 경우 반환 된 MetadataBuffer는 비어 있습니다 (logcat 참조). 앱을 제거한 후을 다시 설치하면 동일한 코드가 예상되는 메타 데이터 개체가있는 MetaDataBuffer를 생성합니다. 이것은 내가 테스트 한 모든 장치에서 발생했습니다. 나는 그것이 로컬 캐시와 관련이 있다고 가정하고있다. 내 코드에서 뭔가 빠졌는 지 궁금하거나 Google에 문제를 제기해야합니다.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...
}
}
};
동일한 문제가 있지만 앱이 intalled 될 때마다 재현 할 수 있습니다. – Simon