ChaturaM
ChaturaM

Reputation: 1557

Android - Google Drive - Can't get results from the query

I am using following tutorial https://google-developers.appspot.com/drive/android/queries?hl=fr-FR

in that, it has following code

Query query = ...;
Drive.DriveApi.query(googleApiClient, query)
        .setResultCallback(new OnChildrenRetrievedCallback() {

    @Override
    public void onChildrenRetrieved(MetadataBufferResult result) {
        // Iterate over the matching Metadata instances in mdResultSet
    }
});

But I can't find OnChildrenRetrievedCallback() method. any help is much appreciated.

Upvotes: 2

Views: 613

Answers (1)

Rivero
Rivero

Reputation: 914

You can use the following code to retrieve the results of the query and iterate through them:

    Query query = new Query.Builder()
            .addFilter(Filters.eq(SearchableField.MIME_TYPE, "text/plain"))
            .build();
    Drive.DriveApi.query(getGoogleApiClient(), query)
            .setResultCallback(metadataCallback);
}

final private ResultCallback<MetadataBufferResult> metadataCallback = new
        ResultCallback<MetadataBufferResult>() {
    @Override
    public void onResult(MetadataBufferResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Problem while retrieving results");
            return;
        }
        mResultsAdapter.clear();
        mResultsAdapter.append(result.getMetadataBuffer());
    }
};

OnChildrenRetrievedCallback() class had been removed in Drive 4.X update. You can still view the old sample implementation in Google's github. The change was made in this commit. The above implementation can be found in this page.

Upvotes: 2

Related Questions