You can use the com.google.android.gms.drive.query package to search a user's
Drive account for files whose metadata match your search criteria. You can
issue a query for a specific folder or on the entire filesystem.
A query is created by building an instance of the
Query class and specifying the search
criteria with Filters.
The following example finds all files with the title "HelloWorld.txt".
Query query = new Query.Builder()
You can use the Filters class to build expressions. Multiple filters can be
joined together using the and and or methods.
Once a Query object has been constructed it can be executed on the entire file
This query starts in the My Drive (the root) folder and recursively
traverses the entire filesystem, returning all entries matching the Filters
A query can alternatively be executed only in a specific folder using the
method, as shown by:
This call does not scan recursively; only direct entries in this folder
matching filter conditions are returned.
Retrieving the result of a query
The result of a query is a list of
Metadata instances for each
of the matching entries. These instances can subsequently be used to
perform additional operations, such as reading a file from the filesystem.
The API supports retrieving the result either synchronously or
The following example demonstrates how to retrieve the results asynchronously:
Alternatively, you can also retrieve the results synchronously. For more
Specifying query conditions
As described above, you can use the Filters class to construct query
parameters that determine what elements to return. Queries support both
boolean and relational operators.
The following example searches for all starred text files:
Query query =
As seen in this example, many instances of Filters can be combined indefinitely
to form the desired expression and specify the evaluation order.
The following table lists the metadata fields that can be queried:
The MIME type of the file
The date the file was last modified
The parent folder(s) of the file or folder
Whether the file is starred or not
The title of the file
Whether the file is trashed
The value of the CustomProperty
Add sorting to a query
class can be used to add sorting to queries. Multiple sorting
fields can be added to a single query; ties from the first sorting field are
broken down by the second sorting field and so on.
The following example adds sort ascending by file title: