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
  - Analyze
  - 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.DriveContentsResult | Result that contains a `DriveContents`.
interface | DriveApi.DriveIdResult | Result that contains a `DriveId`.
interface | DriveApi.MetadataBufferResult | Result that contains a `MetadataBuffer`.

Public Methods
abstract PendingResult<Status> | cancelPendingActions(GoogleApiClient apiClient, List<String> trackingTags) Requests a canceling of the actions identified by the specified tags.
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 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 PendingResult<DriveApi.DriveContentsResult> | newDriveContents(GoogleApiClient apiClient) Retrieves a new `DriveContents` instance that can be used to provide initial contents for a new file.
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> cancelPendingActions (GoogleApiClient apiClient, List<String> trackingTags)

Requests a canceling of the actions identified by the specified tags.

This method does not guarantee that the requested actions will be canceled as some of the actions may be in a state where they can't be canceled anymore.

Only actions originating from this application and from the account set on this client may be canceled by this call.

It is recommended using this method with actions that were performed with `ExecutionOptions` requesting completion notifications, so that for any canceled action a `CompletionEvent` with status `STATUS_CANCELED` is delivered to the application. This way the application may know which actions were actually canceled.

##### Parameters

trackingTags | the list of tracking tags that identify the actions that should be canceled.

##### Returns

- A successful status only indicates that the API received the cancel request, but not that all the requested actions were actually canceled. `CompletionEvent` may be used to track the canceled actions.

#### 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). An error result will be returned if the given resource ID does not exist.

##### 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 `SCOPE_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 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 PendingResult<DriveApi.DriveContentsResult> newDriveContents (GoogleApiClient apiClient)

Retrieves a new `DriveContents` instance that can be used to provide initial contents for a new file. The returned contents will be in `MODE_WRITE_ONLY` and can be used to write the initial contents through the file APIs provided in `DriveContents`.

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

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

##### 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 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.
query | The query that will restrict the contents of the result set.

##### Returns

- A PendingResult which can be used to retrieve the result set. Be sure to call `release()` when you're done with the result.

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

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

This operation may fail with `DRIVE_RATE_LIMIT_EXCEEDED` status, which indicates that the operation may succeed if reattempted after a sufficient backoff duration.

##### Parameters

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