Payload

public classPayloadextendsObject

A Payload sent between devices. Payloads sent as a particular type will be received as that same type on the other device, e.g. the data for a Payload of typePayload.Type.STREAM must be received by reading from the InputStream returned byasStream().

Nested Class Summary

class Payload.File Represents a file in local storage on the device.
class Payload.Stream Represents a stream of data.
@interface Payload.Type The type of this payload.

Public Method Summary

byte[]
asBytes()
Non-null for payloads of type Payload.Type.BYTES.
Payload.File
asFile()
Non-null for payloads of type Payload.Type.FILE.
Payload.Stream
asStream()
Non-null for payloads of type Payload.Type.STREAM.
void
close()
Closes to release anyParcelFileDescriptor andInputStream resources for Payload.Fileor Payload.Streamwhen the transferring stopped.
staticPayload
fromBytes(byte[] bytes)
Creates a Payload of type Payload.Type.BYTESfor sending to another device.
staticPayload
fromFile(ParcelFileDescriptor pfd)
Creates a Payload of type Payload.Type.FILE(backed by aParcelFileDescriptor) for sending to another device; for example, the ParcelFileDescriptor obtained from a call to ContentResolver.openFileDescriptor(Uri, String)for a URI.
staticPayload
fromFile(FilejavaFile)
Creates a Payload of type Payload.Type.FILE(backed by aFile) for sending to another device.
staticPayload
fromStream(ParcelFileDescriptor pfd)
Creates a Payload of type Payload.Type.STREAM(backed by aParcelFileDescriptor) for sending to another device; for example, the read side of a ParcelFileDescriptor pipe to which data is being written by the MediaRecorder API.
staticPayload
fromStream(InputStream inputStream)
Creates a Payload of type Payload.Type.STREAM(backed by anInputStream) for sending to another device; for example, aPipedInputStream connected to aPipedOutputStream to which data is being written.
long
getId()
A unique identifier for this payload.
long
getOffset()
Returns the offset of this payload for resume sending or receiving.
int
getType()
The type of this payload, one of Payload.Type.
void
setFileName(Stringname)
Sets the file name of this Payload.Type.FILEpayload.
void
setOffset(long offset)
Sets the offset from getOffset()when resuming a transfer.
void
setParentFolder(String parentFolder)
Sets the parent folder of this Payload.Type.FILEpayload.
void
setSensitive(boolean isSensitive)
Sets whether or not the payload is sensitive.

Inherited Method Summary

Public Methods

public byte[]asBytes()

Non-null for payloads of typePayload.Type.BYTES.

publicPayload.File asFile()

Non-null for payloads of typePayload.Type.FILE.

publicPayload.Stream asStream()

Non-null for payloads of typePayload.Type.STREAM.

public voidclose()

Closes to release anyParcelFileDescriptor andInputStream resources forPayload.File orPayload.Stream when the transferring stopped.

public staticPayload fromBytes(byte[] bytes)

Creates a Payload of typePayload.Type.BYTES for sending to another device.

public staticPayload fromFile(ParcelFileDescriptor pfd)

Creates a Payload of typePayload.Type.FILE (backed by aParcelFileDescriptor) for sending to another device; for example, the ParcelFileDescriptor obtained from a call to ContentResolver.openFileDescriptor(Uri, String)for a URI.

public staticPayload fromFile(FilejavaFile)

Creates a Payload of typePayload.Type.FILE (backed by aFile) for sending to another device. Note: The file will be saved in the remote device's Downloads folder under a generic name with no extension. The client app on the remote device is responsible for renaming thisFileand adding an appropriate extension, if necessary, and all this (and possibly additional) metadata should be transmitted by the local device out-of-band (likely using a Payload of type Payload.Type.BYTES).

The client app must have any necessary permissions to read the Java file.

public staticPayload fromStream(ParcelFileDescriptor pfd)

Creates a Payload of typePayload.Type.STREAM (backed by aParcelFileDescriptor) for sending to another device; for example, the read side of a ParcelFileDescriptor pipe to which data is being written by the MediaRecorder API.

Nearby Connections will read continuously from the ParcelFileDescriptor (for data to send) until it is closed.

public staticPayload fromStream(InputStream inputStream)

Creates a Payload of typePayload.Type.STREAM (backed by anInputStream) for sending to another device; for example, aPipedInputStream connected to aPipedOutputStream to which data is being written.

Nearby Connections will read continuously from the InputStream (for data to send) until it is closed.

public longgetId()

A unique identifier for this payload.

public longgetOffset()

Returns the offset of this payload for resume sending or receiving.

public intgetType()

The type of this payload, one ofPayload.Type.

public voidsetFileName(Stringname)

Sets the file name of thisPayload.Type.FILE payload. Nearby Connections will pass the file name to the remote device and then the remote device will attempt to save the payload file with the specified file name under the device's download folder.

public voidsetOffset(long offset)

Sets the offset fromgetOffset() when resuming a transfer. The payload will be started to send from the offset. Only supports typePayload.Type.FILE orPayload.Type.STREAM.

public voidsetParentFolder(String parentFolder)

Sets the parent folder of thisPayload.Type.FILE payload. Nearby Connections will pass the parent folder's name to the remote device and then the remote device will create a folder with the specified name under the download folder to save the incoming payload.

public voidsetSensitive(boolean isSensitive)

Sets whether or not the payload is sensitive. This setting is only supported for Payload.Type.FILE. SensitivePayload.Type.FILE payloads will be stored in private storage and cannot be read by apps other than the caller. By default, this option is false.