Represents a file in local storage on the device.
Public Method Summary
File |
asJavaFile()
This method is deprecated. Use
asUri() instead.
|
ParcelFileDescriptor |
asParcelFileDescriptor()
Gets the
ParcelFileDescriptor
from which to read the data of this File; useful when reading the File in a
streaming fashion, before the entire contents have arrived from the remote
endpoint.
|
Uri |
asUri()
Gets a file
Uri for
which the client package has read and write permissions (see
ContentResolver.openInputStream(Uri) or
ContentResolver.openFileDescriptor(Uri, String) ).
|
void |
close()
This method is deprecated. Use
Payload.close() instead.
|
long |
getSize()
Gets the size of this Payload.File in bytes.
|
Inherited Method Summary
Public Methods
public File asJavaFile ()
This method is deprecated.
Use asUri()
instead.
Gets the File
that backs this
File. When receiving a File, this File
will be written
to the device's Downloads folder (as returned by
Environment.getExternalStoragePublicDirectory(String)
), and can then be
copied or moved (read on for how to do this safely) to your app's private storage, if
necessary.
Note that when receiving a Payload.File
,
the call to
PayloadCallback.onPayloadReceived(String, Payload)
occurs at the start of
the data transfer; i.e., at the time of the call, this File
exists but may
not yet contain all of its data. Wait for updates to
PayloadCallback.onPayloadTransferUpdate(String, PayloadTransferUpdate)
to
indicate the transfer has completed before attempting to move the File
. If you want to
read the data as it comes in, use
asParcelFileDescriptor()
to get a streaming interface to the incoming
Payload.File
data.
Note: The file is saved in the local device's Downloads folder under a generic name
with no extension. The client app is responsible for renaming this File
and adding an
appropriate extension, if necessary, and all this (and possibly additional) metadata
should be transmitted by the remote device out-of-band (likely using a Payload of type
Payload.Type.BYTES
).
public ParcelFileDescriptor asParcelFileDescriptor ()
Gets the ParcelFileDescriptor
from which to read the data of this File; useful when reading the File in a streaming
fashion, before the entire contents have arrived from the remote endpoint.
public Uri asUri ()
Gets a file Uri
for which the
client package has read and write permissions (see
ContentResolver.openInputStream(Uri)
or
ContentResolver.openFileDescriptor(Uri, String)
). Read and write permissions
can be persisted across reboots using
ContentResolver.takePersistableUriPermission(Uri, int)
. Alternatively, you
can copy the file contents to a location under your control and delete the original
file. The uri will be non-null when receiving file payloads. When sending file
payloads, the uri may be null, i.e. when the payload is created by
Payload.fromFile(ParcelFileDescriptor)
).
public void close ()
This method is deprecated.
Use Payload.close()
instead.
Closes the ParcelFileDescriptor
to release resource.
public long getSize ()
Gets the size of this Payload.File in bytes. For an incoming File, this is the
expected size of the File
once all data has
been received. For an outgoing File, this is simply the size of the File
or the available
data in the ParcelFileDescriptor
at the time of construction.