java.lang.Object | ||
↳ | com.google.android.gms.common.api.GoogleApi<com.google.android.gms.drive.Drive.ConnectionlessDriveOptions> | |
↳ | com.google.android.gms.drive.DriveResourceClient |
The contract for any DriveResource
(i.e. DriveFile
or DriveFolder
).
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds the specified
listener to be notified of changes to the specified resource . | |||||||||||
Adds a subscription for this
resource that will deliver events to the application's
DriveEventService subclass when changes to this resource are visible to the client. | |||||||||||
Cancels callback passed into
openFile(DriveFile, int, OpenFileCallback) with the
ListenerToken returned from the open() call. | |||||||||||
Commits the
contents and updates its metadata to changeSet (if provided). | |||||||||||
Commits the
contents and updates its metadata to changeSet (if provided). | |||||||||||
Creates a new
DriveContents instance that can be used to provide initial contents for a
new DriveFile . | |||||||||||
Creates a new binary
DriveFile within folder , with the initial metadata
provided in changeSet , initial contents provided in driveContents , and method
execution options provided in executionOptions . | |||||||||||
Creates a new binary
DriveFile within folder , with the initial metadata
provided in changeSet and initial contents provided in driveContents . | |||||||||||
Permanently deletes this
resource , bypassing trash. | |||||||||||
Discards
contents and any changes that were performed on it. | |||||||||||
Returns the app folder.
| |||||||||||
Retrieves the
Metadata associated with this resource . | |||||||||||
Returns the root folder.
| |||||||||||
Retrieves a collection of metadata for the direct children, including both files and folders,
of
folder . | |||||||||||
Retrieves the collection of metadata for all of the parents of this
resource that the
calling app has been authorized to view. | |||||||||||
Retrieves a collection of metadata for the files and folders that match the restrictions
specified in
query . | |||||||||||
Retrieves a collection of metadata for the files and folders that match the restrictions
specified in
query and are direct children of folder . | |||||||||||
Removes the
OnChangeListener associated with this token from listening to
changes to the associated DriveResource . | |||||||||||
Removes the existing Change subscription for this
resource . | |||||||||||
Moves the
resource to trash. | |||||||||||
Moves the
resource out of the trash. | |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Adds the specified listener
to be notified of changes to the specified resource
.
The listener will remain active for the duration of the process or until removeChangeListener(ListenerToken)
is called with the same ListenerToken
returned by
this method.
Parameters | |
---|---|
resource |
DriveResource |
listener |
OnChangeListener |
Returns | |
---|---|
Task<ListenerToken> |
Adds a subscription for this resource
that will deliver events to the application's
DriveEventService
subclass when changes to this resource are visible to the client.
The application's DriveEventService
subclass should implement onChange(ChangeEvent)
in order to handle the incoming ChangeEvent
objects.
The subscription is persistent and will remain active until the next device reboot or until
removeChangeSubscription(DriveResource)
is called. The client is responsible for
registering the subscription again after a device reboot if it is still desired.
Parameters | |
---|---|
resource |
DriveResource |
Returns | |
---|---|
Task<Void> |
Cancels callback passed into openFile(DriveFile, int, OpenFileCallback)
with the
ListenerToken
returned from the open()
call.
Note: The Callback is cancelled for you after onContents(DriveContents)
or onError(Exception)
is called.
Parameters | |
---|---|
token |
ListenerToken |
Returns | |
---|---|
Task<Boolean> |
true if callback was cancelled, false if callback was already cancelled
or not registered in the first place.
|
Commits the contents
and updates its metadata to changeSet
(if provided). This
method should only be used on DriveContents
that are already associated to a particular
DriveFile
, obtained through openFile(DriveFile, int)
.
This method will commit contents using the default CONFLICT_STRATEGY_OVERWRITE_REMOTE
strategy, will not notify for a CompletionEvent
, and will have no tracking tags. If you'd
like to specify different options, use commitContents(DriveContents, MetadataChangeSet, ExecutionOptions)
instead.
After this method returns, contents
will be closed and no longer usable.
Parameters | |
---|---|
contents |
DriveContents |
changeSet |
MetadataChangeSet |
Returns | |
---|---|
Task<Void> |
Throws | |
---|---|
IllegalStateException |
if one of the following is true:
|
Commits the contents
and updates its metadata to changeSet
(if provided). Extra
settings for this action, such as a conflict resolution strategy or completion notification
request, can be specified in executionOptions
. See ExecutionOptions
for a
complete list of options. This method should only be used on DriveContents
that are
already associated to a particular DriveFile
, obtained through openFile(DriveFile, int)
.
A file conflict happens when the written contents are not applied on top of the file revision that Drive originally provided when the contents were read by the application. A conflict could happen when an application reads contents at revision X, then writes revision X+1 and, by the time X+1 is committed or updated on the server, the file version is not X anymore (because, e.g. another app or a remote change already modified the file to revision X').
After this method returns, contents
will be closed and no longer usable.
Parameters | |
---|---|
contents |
DriveContents |
changeSet |
MetadataChangeSet |
executionOptions |
ExecutionOptions |
Returns | |
---|---|
Task<Void> |
Throws | |
---|---|
IllegalStateException |
if one of the following is true:
|
Creates a new DriveContents
instance that can be used to provide initial contents for a
new DriveFile
. The returned contents will be in MODE_WRITE_ONLY
and
can be used to write the initial contents.
To be persisted, the contents must be saved by being passed as an argument to createFile(DriveFolder, MetadataChangeSet, DriveContents)
, {@link
#createFile(DriveFolder, MetadataChangeSet, DriveContents,
ExecutionOptions) or {@link
CreateFileActivityOptions.Builder#setInitialDriveContents(DriveContents)}.
Returns | |
---|---|
Task<DriveContents> |
Creates a new binary DriveFile
within folder
, with the initial metadata
provided in changeSet
, initial contents provided in driveContents
, and method
execution options provided in executionOptions
. In order to create the file with empty
contents, pass in null
for driveContents
. It is recommended that files with a
mime-type that does not support having a zero-byte file (e.g. an image or PDF) is created as a
non-empty file.
Note: setConflictStrategy(int)
is not supported for this
method.
driveContents
must be obtained through createContents()
. Once this method
returns, driveContents
will be persisted and closed. In order to continue editing the
file's contents, they must be opened again with openFile(DriveFile, int)
or openFile(DriveFile, int, OpenFileCallback)
.
If you want to use the default ExecutionOptions
, call createFile(DriveFolder, MetadataChangeSet, DriveContents)
instead.
Parameters | |
---|---|
folder |
DriveFolder |
changeSet |
MetadataChangeSet |
driveContents |
DriveContents |
executionOptions |
ExecutionOptions |
Returns | |
---|---|
Task<DriveFile> |
Creates a new binary DriveFile
within folder
, with the initial metadata
provided in changeSet
and initial contents provided in driveContents
. In order
to create the file with empty contents, pass in null
. It is recommended that files with
a mime-type that does not support having a zero-byte file (e.g. an image or PDF) is created as
a non-empty file.
driveContents
must be obtained through createContents()
. Once this method returns, driveContents
will be persisted and closed. In order to continue editing the file's
contents, they must be opened again with openFile(DriveFile, int)
or openFile(DriveFile, int, OpenFileCallback)
.
This method behaves like createFile(DriveFolder, MetadataChangeSet, DriveContents, ExecutionOptions)
with {@code null {@link ExecutionOptions}, which means completion event
notifications will not be sent and there is no operation tag.
Parameters | |
---|---|
folder |
DriveFolder |
changeSet |
MetadataChangeSet |
driveContents |
DriveContents |
Returns | |
---|---|
Task<DriveFile> |
Creates a new DriveFolder
within folder
, with the initial metadata provided in
changeSet
.
Note: At minimum, setTitle(String)
must be called.
setMimeType(String)
does not need to be called, as the
mime-type will automatically be set to MIME_TYPE
.
Parameters | |
---|---|
folder |
DriveFolder |
changeSet |
MetadataChangeSet |
Returns | |
---|---|
Task<DriveFolder> |
Permanently deletes this resource
, bypassing trash. The user must be the owner. If
resource
is a DriveFolder
, the app must have access to all of its descendants.
For user-visible resources, we recommend using trash(DriveResource)
instead to give
users the opportunity to restore files they have accidentally removed.
Delete must be used for files in the App Folder as they cannot be trashed. See getAppFolder()
for more information.
Parameters | |
---|---|
resource |
DriveResource |
Returns | |
---|---|
Task<Void> |
Discards contents
and any changes that were performed on it. Calling this method will
not save any changes performed on this object.
After this method returns, contents
will be closed and no longer usable.
Parameters | |
---|---|
contents |
DriveContents |
Returns | |
---|---|
Task<Void> |
Returns the app folder.
The app folder is a special folder within Drive that is only accessible by your application. Its contents are hidden from the user and from other apps. Although it is hidden from the user, the app folder does count against the user's Drive storage quota.
The app folder can be used to store configuration files, temporary files, etc. that belong to the user but should not be tampered with.
SCOPE_APPFOLDER
is required to access this folder; otherwise, it fails with
the error status DEVELOPER_ERROR
.
See the Storing Application Data guide for more information.
Returns | |
---|---|
Task<DriveFolder> |
Returns the root folder.
SCOPE_FILE
is required to access this folder; otherwise, it fails with the
error status DEVELOPER_ERROR
.
Returns | |
---|---|
Task<DriveFolder> |
Retrieves a collection of metadata for the direct children, including both files and folders,
of folder
.
Be sure to call release()
when finished with the result.
Parameters | |
---|---|
folder |
DriveFolder |
Returns | |
---|---|
Task<MetadataBuffer> |
Retrieves the collection of metadata for all of the parents of this resource
that the
calling app has been authorized to view.
Be sure to call release()
when finished with the result.
Parameters | |
---|---|
resource |
DriveResource |
Returns | |
---|---|
Task<MetadataBuffer> |
Opens the DriveContents
that are associated with this file
in the requested
openMode
. The returned contents is a temporary copy available only to this app. The
contents must be closed via commitContents(DriveContents, MetadataChangeSet)
or discardContents(DriveContents)
.
Note: To open the file in edit mode, the user must have edit access. See isEditable()
for more information.
The contents are returned when they are available on the device in their entirety. Content is returned from the cache if it is available and up-to-date; otherwise, it will be downloaded from the server.
Note: If the download fails (e.g. due to the device going offline) the cached version will be returned if available.
Parameters | |
---|---|
file |
DriveFile |
openMode |
int |
Returns | |
---|---|
Task<DriveContents> |
Opens the DriveContents
that are associated with this file
in the requested
openMode
. The provided OpenFileCallback
will receive a temporary copy of the
contents available only to this app. The contents must be closed via commitContents(DriveContents, MetadataChangeSet)
or
discardContents(DriveContents)
. The returned ListenerToken
can be used to cancel the
download.
Note: To open the file in edit mode, the user must have edit access. See isEditable()
for more information.
Note: If the download fails (e.g. due to the device going offline) the cached version will be returned if available.
Parameters | |
---|---|
file |
DriveFile |
openMode |
int |
callback |
OpenFileCallback |
Returns | |
---|---|
Task<ListenerToken> |
Retrieves a collection of metadata for the files and folders that match the restrictions
specified in query
.
Be sure to call release()
when finished with the result.
Parameters | |
---|---|
query |
Query |
Returns | |
---|---|
Task<MetadataBuffer> |
Retrieves a collection of metadata for the files and folders that match the restrictions
specified in query
and are direct children of folder
.
Be sure to call release()
when finished with the result.
Parameters | |
---|---|
folder |
DriveFolder |
query |
Query |
Returns | |
---|---|
Task<MetadataBuffer> |
Removes the OnChangeListener
associated with this token
from listening to
changes to the associated DriveResource
. The token
must be the same ListenerToken
that was returned by addChangeListener(DriveResource, OnChangeListener)
.
Returns true
if removing the listener was successful.
Parameters | |
---|---|
token |
ListenerToken |
Returns | |
---|---|
Task<Boolean> |
Removes the existing Change subscription for this resource
.
Parameters | |
---|---|
resource |
DriveResource |
Returns | |
---|---|
Task<Void> |
Closes the contents
and returns a new DriveContents
opened in MODE_WRITE_ONLY
. The returned contents are usable for conflict detection.
After this method returns, contents
will be closed and will no longer be usable
This method is often used in conjunction with commitContents(DriveContents, MetadataChangeSet)
.
Parameters | |
---|---|
contents |
DriveContents |
Returns | |
---|---|
Task<DriveContents> |
Throws | |
---|---|
IllegalStateException |
if this method is called on contents that are currently opened in
MODE_WRITE_ONLY or MODE_READ_WRITE or on contents that
have been closed
|
Sets the parents of resource
to the DriveId
instances defined in parentIds
. This will overwrite the current parent IDs with parentIds
, so any parent
IDs that should remain as parents but also be supplied in the Set. Do NOT modify parentIds
after calling this method.
All parent IDs must be associated with DriveFolder
resources.
If this resource
is in the App Folder or one of its subfolders, all parents must
also belong to the App Folder or one of its subfolders. Similarly, if this resource
is
outside of the App Folder, every parent must also be outside of the App Folder.
Parameters | |
---|---|
resource |
DriveResource |
parentIds |
Set |
Returns | |
---|---|
Task<Void> |
Moves the resource
to trash. The user must be the owner. If the resource is a DriveFolder
, the app must have access to all of its descendants.
Resources inside the App Folder cannot be trashed. See getAppFolder()
for more
information.
Parameters | |
---|---|
resource |
DriveResource |
Returns | |
---|---|
Task<Void> |
Moves the resource
out of the trash. The user must be the owner. If the resource is a
DriveFolder
, the app must have access to all of its descendants.
Resources inside the App Folder cannot be untrashed (because they cannot be trashed). See
getAppFolder()
for more information.
Parameters | |
---|---|
resource |
DriveResource |
Returns | |
---|---|
Task<Void> |
Updates the Metadata
that is associated with this resource
with the changes
defined in changeSet
.
Note that the user must have edit access to update certain metadata fields. See MetadataChangeSet.Builder
for more information.
Note that the metadata of the root folder cannot be updated.
Parameters | |
---|---|
resource |
DriveResource |
changeSet |
MetadataChangeSet |
Returns | |
---|---|
Task<Metadata> |