DriveId
DrivéContents
. The bináry content material ofa file is usually encapsulated in théDriveContents
lnputStream
andParcelFileDescriptor
course is generally greatest suitedfor applications with dependencies ór native-code thát make use of aFileDescriptor
.DriveFile
object:lnputStream
or théParcelFileDescriptor
DriveContents
source inDriveFiIe.MODEREADONLY
órDriveFile.M0DEREADWRITE
mode, based on whether you choose to work withthelnputStream
orParcelFileDescriptorclass.Take note:ThéInputStream
class is only obtainable for documents opened up inREADONLY
setting. Files opened up withREADWRlTE
must use theParcelFileDescriptor
course to read through from the file.DriveResourceClient.openFiIe
method retrieves the in your area synced fileresource and starts it. If the document is not synced with the nearby storage,it retrieves the file from the Get support and results aDriveContents
source. For illustration:DriveContents
source includes a short-term duplicate of the document's binary streamthat is certainly only accessible to your application. If multiple applications try toaccess the same document, there are no competition problems betweenDriveContents
sources. In this situation, the final write operation is definitely the finalstate of the articles.DriveContents
resource. Thisresource includes methods to obtain anlnputStream
orParcelFileDescriptortó read through the file's binary items.The following example shows how to retrieve a document'sDrivéContents
:0penFileCallback
to inform users of thedownload progress in aProgressDialogtó improve the consumer experience.To pay attention to the download improvement, open up the document contents with aDownloadProgressListener, ás shown in this instance:coffee.io.InputStream
DrivéContents
source and transform the binary items into aThread
item. However, you can consume the insight stream in whatever way yourapplication and data format réquire.0utputStream
or théParcelFileDescriptor
OutputStream
course is only obtainable for data files opened inWRITEONLY
setting. Files opened up withREADWRlTE
must use theParcelFileDescriptor
course to compose to the document.DriveFiIe.MODEREADWRITE
tó open up the material in a writable setting, based on whether you mean tooverwrite the content with anOutputStreamór append to thé articles with aParcelFileDescriptor
. You can optionally make use of a0penFileCallback
tolisten tó the download státusif the most recent version of the document is not already synced to the device.DriveContents
source offers acoffee.io.OutputStream
that lets you writeor append binary data to the file items.Be aware:Documents opened up inWRITEONLY
setting are usually truncated before anything will be created tothe file. To append to a document open up it inDriveContents
reference will be a short-term copy of the file you are tryingto modify and is certainly only accessible within your application. As soon as you're donewith the output stream, you must either splurge any modifications that you produced, makingthem visible in the user's Get, or discard the changes.The next section shows how to complete the write operation.DriveContents
resource to free associated resources,notifying the system whether you would like to keep or throw away any adjustments made. Inorder the keep the modifications permanently, use theDriveResourceCIient.commitContents
method, transferring in theDriveContentsobject to close.Notice:If you open up a file read-only setting, doing and getting rid of thecontents are usually similar, because no modifications can be produced.DriveContents
resource, make use of theDriveResourceCIient.discardContents
method to avoid writing changes to the document in the consumer's Commute.