DriveFile | 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...
Summary: Nested Classes | Constants | Methods | Inherited Methods | [Expand All]
public interface

# DriveFile

implements DriveResource

com.google.android.gms.drive.DriveFile

## Class Overview

A file in Drive. This class provides access to the contents and metadata of the specified file. To retrieve a DriveFile from a known drive id, use `getFile(GoogleApiClient, DriveId)`.

## Summary

Nested Classes
interface | DriveFile.DownloadProgressListener | A listener that listens for progress events on an active contents download.

Constants
int | MODE_READ_ONLY | A mode that opens the contents only for reading.
int | MODE_READ_WRITE | A mode that opens the contents for reading and writing.
int | MODE_WRITE_ONLY | A mode that opens the contents only for writing.

Public Methods
abstract PendingResult<DriveApi.DriveContentsResult> | open(GoogleApiClient apiClient, int mode, DriveFile.DownloadProgressListener listener) Opens the `DriveContents` that are associated with this file for read and/or write.

[Expand] Inherited Methods
From interface com.google.android.gms.drive.DriveResource
abstract PendingResult<Status> | addChangeListener(GoogleApiClient apiClient, ChangeListener listener) Adds a new listener for changes on this resource.
abstract PendingResult<Status> | addChangeSubscription(GoogleApiClient apiClient) Adds a change subscription for this resource that will deliver events to the application event service.
abstract DriveId | getDriveId() Returns the DriveId that uniquely identifies this resource.
abstract PendingResult<DriveResource.MetadataResult> | getMetadata(GoogleApiClient apiClient) Retrieves the Metadata associated with this resource.
abstract PendingResult<DriveApi.MetadataBufferResult> | listParents(GoogleApiClient apiClient) Retrieves a collection of metadata for all of the parents of this resource that the calling app has been authorized to view.
abstract PendingResult<Status> | removeChangeListener(GoogleApiClient apiClient, ChangeListener listener) Removes a listener for changes on this resource that was previously added by `addChangeListener(GoogleApiClient, ChangeListener)`.
abstract PendingResult<Status> | removeChangeSubscription(GoogleApiClient apiClient) Removes any existing change subscription for this resource.
abstract PendingResult<Status> | setParents(GoogleApiClient apiClient, Set<DriveId> parentIds) Sets the parents of this resource.
abstract PendingResult<Status> | trash(GoogleApiClient apiClient) Moves the resource to trash.
abstract PendingResult<Status> | untrash(GoogleApiClient apiClient) Moves the resource out of the trash.
abstract PendingResult<DriveResource.MetadataResult> | updateMetadata(GoogleApiClient apiClient, MetadataChangeSet changeSet) Updates the Metadata that is associated with this resource with the changes described in the `MetadataChangeSet`.

## Constants

#### public static final int MODE_READ_ONLY

A mode that opens the contents only for reading.

Constant Value: 268435456 (0x10000000)

#### public static final int MODE_READ_WRITE

A mode that opens the contents for reading and writing.

Constant Value: 805306368 (0x30000000)

#### public static final int MODE_WRITE_ONLY

A mode that opens the contents only for writing.

Constant Value: 536870912 (0x20000000)

## Public Methods

#### public abstract PendingResult<DriveApi.DriveContentsResult> open (GoogleApiClient apiClient, int mode, DriveFile.DownloadProgressListener listener)

Opens the `DriveContents` that are associated with this file for read and/or write. The returned file is a temporary copy available only to this app. The contents are returned when they are available on the device in their entirety. To listen for progress, provide a `DriveFile.DownloadProgressListener`.

The contents must be closed via `commit(GoogleApiClient, MetadataChangeSet)` or `discard(GoogleApiClient)`.

Note: to open the file in edit mode, the user must have edit access. See `isEditable()`.

##### Parameters

apiClient | The `GoogleApiClient` to service the call.
mode | Describes the mode in which to open the file. Possible values are `MODE_READ_ONLY`, `MODE_READ_WRITE` and `MODE_WRITE_ONLY`.
listener | An optional listener that will announce progress as the file is downloaded. If you don't care about progress, provide `null`.

##### Returns

- A PendingResult which can be used to retrieve the `DriveContents` when they are available. If `isSuccess()` returns true, it is recommended to check `getStatusCode()`, since two possible values are considered success: `SUCCESS` which means that the returned `DriveContents` is up to date, or `SUCCESS_CACHE` which means that the returned `DriveContents` is a cached version, since the most up to date version could not be downloaded to the device (for example, due to connectivity).