Reputation: 389
I'm using this piece of code to check whether a file exists in Drive:
Query query = new Query.Builder()
.addFilter(Filters.eq(SearchableField.TITLE, "tmp.txt"))
.build();
new MyAsyncTask().execute(query);
class MyAsyncTask extends AsyncTask<Query, Void, MetadataBufferResult>{
@Override
protected MetadataBufferResult doInBackground(Query... params) {
return Drive.DriveApi.query(getGoogleApiClient(), params[0]).await();
}
@Override
protected void onPostExecute(MetadataBufferResult metadataBufferResult) {
if(metadataBufferResult.getMetadataBuffer().getCount()==0)
showMessage("File does not exist");
else
showMessage("File exists");
}
}
My logic basically is to use a Query to filter out all files with name "tmp.txt" and then check if the count of the thus returned MetaDataBuffer is not 0. However, whether or not the file exists, the count is always 0 and the message is displayed as "File does not exist". What am I missing here? I'm using a modified version of QueryFilesActivity from the android-demo-master provided by Android.
Upvotes: 1
Views: 1045
Reputation: 213
There are 3 reasons why the query returns 0 items:
Upvotes: 1