Get Started

DeviceListener Interface Reference

Overview

  • Package: com.twilio.client

The DeviceListener interface defines a set of callbacks for events related to a Device instance.

Tasks

Name Description Type
onStartListening Called when the Device has started listening for incoming connections. Instance method
onStopListening Called when the Device has stopped listening for incoming connections. Instance method
onStopListening Called when the Device has stopped listening for incoming connections due to an error condition. Instance method
receivePresenceEvents Called to query whether or not the application wants to receive presence events. Instance method
onPresenceChanged Called when the presence status for one or more other clients has changed. Instance method

Methods

void onStartListening(Device inDevice)

Called when the Device has started listening for incoming connections.

Parameters
Name Description
inDevice The Device instance that has started listening
Return Value

None


void onStopListening(Device inDevice)

Called when the Device has stopped listening for incoming connections.

Parameters
Name Description
inDevice The device instance that has stopped listening
Return Value

None


void onStopListening(Device inDevice, int inErrorCode, String inErrorMessage)

Called when the Device has stopped listening for incoming connections due to an error condition.

For a list of error codes and their meanings, see http://www.twilio.com/docs/client/errors.

Parameters
Name Description
inDevice The device instance that has stopped listening
inErrorCode The error code that pinpoints the error
inErrorMessage A string describing the error in a human-readable form
Return Value

None


boolean receivePresenceEvents(Device inDevice)

Called to query whether or not the application wants to receive presence events.

Since bandwidth and battery life can both be precious resources on a mobile device, you may not want to incur the extra overhead of receiving and processing presence notifications. If not, simply implement this method and return false from it. You'll still need to implement DeviceListener.onPresenceChanged(), of course, but an empty body will do, and it will never be called.

Parameters
Name Description
inDevice The Device querying about presence notifications
Return Value

Whether or not the application wants to receive presence events


void onPresenceChanged(Device inDevice, PresenceEvent inPresenceEvent)

Called when the presence status for one or more other clients has changed.

When the device is ready, this method is invoked once for each available client if .receivePresenceEvents() returns true. Thereafter it is invoked as clients become available or unavailable.

A client is considered available even if another call is in progress.

When your client disconnects the DeviceListener.onStopListening() method will be invoked, and when the device reconnects this method will be called again for every available online client.

The PresenceEvent object may be reused in between calls, so any data required to persist past the invocation of this method should be copied out.

Parameters
Name Description
inDevice The Device receiving the presence change notification
inPresenceEvent A PresenceEvent object describing the notification
Return Value

None