DeviceListener Interface Reference - Twilio
Register for SIGNAL by 8/31 for $250 off. Register now.

DeviceListener Interface Reference

Deprecation Notice

The Twilio Client SDK for Android has been deprecated and replaced by Twilio's Programmable Voice SDK.

The Programmable Voice SDK offers many improvements over the Twilio Client SDK, including greater stability, improved backgrounding, and built-in support for push notifications for incoming calls.

 

If you're just getting started with a Twilio mobile application for voice calling, we recommend you use the Programmable Voice SDK. If you're already using the Twilio Client SDK, you should plan to upgrade to the Programmable Voice SDK as soon as you're able.

Get started with the new Programmable Voice SDK by checking out the quickstart for Programmable Voice SDK for Android on Github.

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

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.