DriveApi | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Tools & Reference
  - Developer Stories

## Results

Loading...
public interface

# DriveApi

com.google.android.gms.drive.DriveApi

## Class Overview

The main entry point for interacting with Drive. This class provides methods for obtaining a reference to a file or folder, or querying across the entire Drive.

## Summary

Nested Classes
interface | DriveApi.ContentsResult | Result that contains a Contents reference.
interface | DriveApi.DriveIdResult | Result that contains a DriveId.
interface | DriveApi.MetadataBufferResult | Result that contains a MetadataBuffer.

Public Methods
abstract PendingResult<Status> | discardContents(GoogleApiClient apiClient, Contents contents) Closes the provided contents without saving the results.
abstract PendingResult<DriveApi.DriveIdResult> | fetchDriveId(GoogleApiClient apiClient, String resourceId) Retrieves a `DriveId` object that can be used in further drive api operations (e.g.
abstract DriveFolder | getAppFolder(GoogleApiClient apiClient) Retrieves a `DriveFolder` object that can be used to interact with the App Folder.
abstract DriveFile | getFile(GoogleApiClient apiClient, DriveId id) Retrieves a `DriveFile` object that can be used to interact with the file specified by the provided DriveId.
abstract DriveFolder | getFolder(GoogleApiClient apiClient, DriveId id) Retrieves a `DriveFolder` object that can be used to interact with the folder specified by the provided DriveId.
abstract DriveFolder | getRootFolder(GoogleApiClient apiClient) Retrieves a `DriveFolder` object that can be used to interact with the root folder.
abstract PendingResult<DriveApi.ContentsResult> | newContents(GoogleApiClient apiClient) Retrieves a new contents instance that can be used to provide initial contents for a new file.
abstract CreateFileActivityBuilder | newCreateFileActivityBuilder() Creates a builder for a Create File activity where a user can select a file name and destination for a new binary file in their Drive with the contents and additional metadata provided in the builder.
abstract OpenFileActivityBuilder | newOpenFileActivityBuilder() Creates a builder for an Open File activity that allows user selection of a Drive file.
abstract PendingResult<DriveApi.MetadataBufferResult> | query(GoogleApiClient apiClient, Query query) Retrieves a collection of metadata for the files and folders that match the specified query.
abstract PendingResult<Status> | requestSync(GoogleApiClient apiClient) Requests synchronization a `PendingResult` that is ready when synchronization has completed.

## Public Methods

#### public abstract PendingResult<Status> discardContents (GoogleApiClient apiClient, Contents contents)

Closes the provided contents without saving the results.

##### Parameters

apiClient | The `GoogleApiClient` to service the call. The client must be connected before invoking this method.
contents | The contents to discard.

##### Returns

- a PendingResult which can be used to verify the success of the operation.

#### public abstract PendingResult<DriveApi.DriveIdResult> fetchDriveId (GoogleApiClient apiClient, String resourceId)

Retrieves a `DriveId` object that can be used in further drive api operations (e.g. getFile, getFolder).

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
resourceId | The Drive resource id for the DriveId to retrieve.

##### Returns

- a PendingResult which can be used to retrieve the DriveId object.

#### public abstract DriveFolder getAppFolder (GoogleApiClient apiClient)

Retrieves a `DriveFolder` object that can be used to interact with the App Folder. This method will return synchronously, and is safe to invoke from the UI thread. The AppData scope is required to access this folder. If the app does not have `DRIVE_APPFOLDER` it will return null.

##### Parameters

apiClient | The `GoogleApiClient` to service the call. The client must be connected using `connect()` before invoking this method.

#### public abstract DriveFile getFile (GoogleApiClient apiClient, DriveId id)

Retrieves a `DriveFile` object that can be used to interact with the file specified by the provided DriveId.

##### Parameters

apiClient | The `GoogleApiClient` to service the call. The client must be connected using `connect()` before invoking this method.

#### public abstract DriveFolder getFolder (GoogleApiClient apiClient, DriveId id)

Retrieves a `DriveFolder` object that can be used to interact with the folder specified by the provided DriveId.

##### Parameters

apiClient | The `GoogleApiClient` to service the call. The client must be connected using `connect()` before invoking this method.

#### public abstract DriveFolder getRootFolder (GoogleApiClient apiClient)

Retrieves a `DriveFolder` object that can be used to interact with the root folder. This method will return synchronously, and is safe to invoke from the UI thread.

##### Parameters

apiClient | The `GoogleApiClient` to service the call. The client must be connected using `connect()` before invoking this method.

#### public abstract PendingResult<DriveApi.ContentsResult> newContents (GoogleApiClient apiClient)

Retrieves a new contents instance that can be used to provide initial contents for a new file. Write the initial contents to the Contents object returned by this request using the file APIs provided in `Contents`.

To be persisted, the contents must be saved by being passed as initial contents to `createFile(GoogleApiClient, MetadataChangeSet, Contents)` or `setInitialContents(Contents)`.

To discard the contents without saving them, invoke `discardContents(GoogleApiClient, Contents)`.

##### Parameters

apiClient | The `GoogleApiClient` to service the call. The client must be connected using `connect()` before invoking this method.

##### Returns

- a PendingResult which can be used to retrieve the Contents object.

#### public abstract CreateFileActivityBuilder newCreateFileActivityBuilder ()

Creates a builder for a Create File activity where a user can select a file name and destination for a new binary file in their Drive with the contents and additional metadata provided in the builder.

#### public abstract OpenFileActivityBuilder newOpenFileActivityBuilder ()

Creates a builder for an Open File activity that allows user selection of a Drive file. Upon completion, the result Intent will contain the `DriveId` for the selected file. This activity will authorize the requesting app to interact with the selected file.

#### public abstract PendingResult<DriveApi.MetadataBufferResult> query (GoogleApiClient apiClient, Query query)

Retrieves a collection of metadata for the files and folders that match the specified query.

##### Parameters

apiClient | The `GoogleApiClient` to service the call. The client must be connected using `connect()` before invoking this method.
query | The query that will restrict the contents of the result set.

##### Returns

- a PendingResult which can be used to retrieve the children list.

#### public abstract PendingResult<Status> requestSync (GoogleApiClient apiClient)

Requests synchronization a `PendingResult` that is ready when synchronization has completed.

##### Parameters

apiClient | The `GoogleApiClient` to service the call. The client must be connected before invoking this method.