Payload

public class Payload extends Object

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 type STREAM must be received by reading from the InputStream returned by asStream().

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 BYTES.
Payload.File
asFile()
Non-null for payloads of type FILE.
Payload.Stream
asStream()
Non-null for payloads of type STREAM.
static Payload
fromBytes(byte[] bytes)
Creates a Payload of type BYTES for sending to another device.
static Payload
fromFile(ParcelFileDescriptor pfd)
Creates a Payload of type FILE (backed by a ParcelFileDescriptor) for sending to another device; for example, the ParcelFileDescriptor obtained from a call to openFileDescriptor(Uri, String) for a URI.
static Payload
fromFile(File javaFile)
Creates a Payload of type FILE (backed by a File) for sending to another device.
static Payload
fromStream(ParcelFileDescriptor pfd)
Creates a Payload of type STREAM (backed by a ParcelFileDescriptor) for sending to another device; for example, the read side of a ParcelFileDescriptor pipe to which data is being written by the MediaRecorder API.
static Payload
fromStream(InputStream inputStream)
Creates a Payload of type STREAM (backed by an InputStream) for sending to another device; for example, a PipedInputStream connected to a PipedOutputStream to which data is being written.
long
getId()
A unique identifier for this payload.
int
getType()
The type of this payload, one of Payload.Type.

Inherited Method Summary

Public Methods

public byte[] asBytes ()

Non-null for payloads of type BYTES.

public Payload.File asFile ()

Non-null for payloads of type FILE.

public Payload.Stream asStream ()

Non-null for payloads of type STREAM.

public static Payload fromBytes (byte[] bytes)

Creates a Payload of type BYTES for sending to another device.

public static Payload fromFile (ParcelFileDescriptor pfd)

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

public static Payload fromFile (File javaFile)

Creates a Payload of type FILE (backed by a File) 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 this File and 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 BYTES).

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

public static Payload fromStream (ParcelFileDescriptor pfd)

Creates a Payload of type STREAM (backed by a ParcelFileDescriptor) 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 static Payload fromStream (InputStream inputStream)

Creates a Payload of type STREAM (backed by an InputStream) for sending to another device; for example, a PipedInputStream connected to a PipedOutputStream to which data is being written.

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

public long getId ()

A unique identifier for this payload.

public int getType ()

The type of this payload, one of Payload.Type.