The Drive Android API is a native API that conforms to standard Android best practices and coding conventions. It is an improvement over the generated client API, simplifying many common tasks associated with using the Drive service on mobile devices. The API automatically handles previously complex tasks such as offline access and syncing files. This allows you to read and write files as if Drive were a local file system.
The Drive Android API also significantly reduces the installed size of Drive-enabled apps. Because the API is part of the Google Play services client library, you no longer need to compile your app using the Google APIs Client Library for Java in order to access the Drive service.
The Google Drive Android API provides abstractions for managing file content
and metadata. Files are represented by the
folders by the
Both share a common
DriveId. This is the
unique identifier for all files and folders.
Metadata for resources are encapsulated in the
Metadata class that contains
all details about a file or folder including the title, the MIME type, and
whether the file is editable, starred or trashed. The Metadata is fetched for a
DriveResource by calling the
The Metadata may be set or changed when creating or updating a file using
MetadataChangeSet and setting
the appropriate values, then calling the
For more information, see Working with Metadata.
You can open files programmatically using the
DriveResourceClient.openFile() method or by allowing the
user to select a file using a file selector activity created with the
The file contains a reference to the contents of the file, encapsulated in the
DriveContents class, which provides
access to read and write the underlying data. You can read the contents of a
drive file by accessing an input stream of its contents by calling
To create a file, you can use either the
method or the
method, which presents a dialog to the user that allows them to create the new
file in their Drive.
The Drive for Android API has several methods for manipulating folders:
DriveResourceClient.createFile(), methods for creating folders or files, respectively, within a folder
DriveResourceClient.queryChildren()methods for listing or querying the children of a folder.
For more information, see Working with Folders.
The Drive for Android API has two methods that implement UI components to simplify common tasks associated with opening and creating files.
helps you quickly create a file, set its initial folder, title, contents, and
metadata. The class also implements a simple UI that allows a user to specify
the file's title and destination folder. For more information, see
helps you easily open a file selected by the user.
The class displays a simple UI to let the user navigate and select from a list
of files that match the specified MIME types.
When you invoke the class, you specify an initial folder where the user's
navigation begins. You can also specify a preferred
set of MIME types for the file list.
Queries allow you to search for specific files or folders based on their
metadata attributes, such as the title. Queries are represented by the
Query class and can be constructed
For more information, see Querying for Files.