2014-07-24 3 views
1

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

      } 
     }; 
+0

동일한 문제가 있지만 앱이 intalled 될 때마다 재현 할 수 있습니다. – Simon

답변

0

로컬 동기화 처리 조금 취
여기 완전한 코드이다. 완료되기 전에 요청하면 불완전한 결과가 나올 수 있습니다. requestSync을 사용하면 동기화가 완료 될 때까지 기다릴 수 있습니다. (이미 요청이 진행 중일 때이 요청은 제한적으로 처리되기도하지만, 우리는이 문제를 개선하기 위해 노력하고 있습니다.)

+0

requestSync가 해결하는 것 같습니다. 문제. 힌트를 주셔서 대단히 감사합니다. – devrocca

+0

"requestSync"에 어떻게 예제를 쓸 수 있습니까? – Michal

+0

@Michal 그냥'Drive.DriveApi.requestSync (googleApiClient)'를 호출하십시오. 그러나 요청 제한은 매우 제한적이라는 경고를받습니다. 호출 사이에 1 분 미만이 걸리면 'DriveStatusCodes.DRIVE_RATE_LIMIT_EXCEEDED' 오류가 발생합니다. 지연은 문서화되어 있지 않으며 기기간에 앱 데이터를 동기화하는 것을 비실용적으로 만듭니다. – sorianiv

관련 문제