Get Started

Connection Interface Reference

Overview

  • Package: com.twilio.client
  • Implemented interfaces: Parcelable

A Connection object represents the connection between a Device and Twilio's services.

A Connection is either incoming or outgoing.

You do not create a Connection directly; an outgoing connection is created by calling the Device.connect() method. Incoming connections are created internally by a Device and handed to the registered incoming PendingIntent registered via Device.setIncomingIntent().

Nested Classes

Tasks

Name Description Type
IncomingParameterFromKey String representing the calling party. If the caller is a telephone, Field
IncomingParameterToKey String representing the client name of the called party. This is in a URI format "client:name". Field
IncomingParameterAccountSIDKey String representing the account id making the incoming call. Field
IncomingParameterAPIVersionKey String representing the version of the Twilio API used in the server application. Field
IncomingParameterCallSIDKey String representing a unique identifier for the incoming call. Field
getState Retrieves the current state of the connection. Instance method
getParameters Retrieves the set of application parameters associated with this connection. Instance method
isIncoming A boolean representing if the Connection is an incoming or outgoing connection. Instance method
accept Accepts an incoming connection request. Instance method
ignore Ignores an incoming connection request. Instance method
reject Rejects an incoming connection request. Instance method
disconnect Disconnect the connection. Instance method
setMuted Mutes or unmutes the microphone's audio for the connection. Instance method
isMuted Reports whether the microphone's audio for the connection is muted. Instance method
sendDigits Send a string of digits over the connection. Instance method
setConnectionListener Sets the ConnectionListener to receive connection state events. Instance method

Fields

IncomingParameterFromKey

String representing the calling party. If the caller is a telephone, it will be in the E.164 format. If the caller is another Twilio Client, it will be in a URI format "client:name".

IncomingParameterToKey

String representing the client name of the called party. This is in a URI format "client:name".

IncomingParameterAccountSIDKey

String representing the account id making the incoming call.

IncomingParameterAPIVersionKey

String representing the version of the Twilio API used in the server application.

IncomingParameterCallSIDKey

String representing a unique identifier for the incoming call.

Methods

State getState()

Retrieves the current state of the connection.

Return Value

The connection state, as a State enum value


Map<> getParameters()

Retrieves the set of application parameters associated with this connection.

Incoming connection parameters are defined by set of values described by the constants in this interface that start with IncomingParameter.

Outgoing connection parameters are defined by the union of optional application parameters specified in the Capability Token and any additional parameters specified when the Device.connect() method is called.

Return Value

an unmodifiable Map of key/value pairs for the Connection, or null if no parameters were set.


boolean isIncoming()

A boolean representing if the Connection is an incoming or outgoing connection.

Return Value

true if the connection is an incoming connection, false if outgoing


void accept()

Accepts an incoming connection request.

When an incoming connection is received, and your PendingIntent is activated, calling this method will accept the incoming connection. Calling this method on a Connection that is not in the State state will have no effect.

Return Value

None


void ignore()

Ignores an incoming connection request.

The caller will receive no notification that the call was ignored.

When an incoming connection is received, and your PendingIntent is activated, calling ignore will close the incoming connection request and the connection may not be accepted. Calling this method on a Connection that is not in the State state will have no effect. The ConnectionListener will eventually receive a ConnectionListener.onDisconnected() callback once the connection is terminated.

Return Value

None


void reject()

Rejects an incoming connection request.

The caller may receive a notification that the call was rejected.

When an incoming connection is received, and your PendingIntent is activated, calling reject will terminate the request, notifying the caller that the call was rejected. Calling this method on a Connection that is not in the State state will have no effect. The ConnectionListener will eventually receive a ConnectionListener.onDisconnected() callback once the connection is terminated.

Return Value

None


void disconnect()

Disconnect the connection.

Calling this method on a Connection that is in the State state will have no effect. The ConnectionListener will eventually receive a ConnectionListener.onDisconnected() callback once the connection is terminated.

Return Value

None


void setMuted(boolean muted)

Mutes or unmutes the microphone's audio for the connection.

Parameters
Name Description
muted true to mute, false to unmute
Return Value

None


boolean isMuted()

Reports whether the microphone's audio for the connection is muted.

Return Value

true if the audio is muted, false otherwise.


void sendDigits(String inDigitsString)

Send a string of digits over the connection.

Valid digits are '0' - '9', '*', '#', and 'w'. Each 'w' will cause a 500 ms pause between digits sent. If any invalid character is present, no digits will be sent.

Calling this method on a Connection that not is in the State state will have no effect.

Parameters
Name Description
inDigitsString a String of one or more valid digits and optional 'w' chars.
Return Value

None


void setConnectionListener(ConnectionListener inListener)

Sets the ConnectionListener to receive connection state events.

Parameters
Name Description
inListener The ConnectionListener object
Return Value

None