public abstract class Device
extends java.lang.Object
implements android.os.Parcelable
Twilio.createDevice(String, DeviceListener)
factory method with a Capability Token to talk to Twilio services.
A Capability Token is a JSON Web Token (JWT) that specifies what the Device may do with respect to the Twilio Application,
such as whether it can make outgoing calls, how long the token and the Device are valid before needing to be refreshed,
and so on.
Please visit http://www.twilio.com/docs/client/capability-tokens
for more information.DeviceListener
Modifier and Type | Class and Description |
---|---|
static class |
Device.Capability
This enum is used as keys to the Device's capabilities map.
|
static class |
Device.State
The Device.State enum represents the various states of the device's ability to listen for incoming connections and make outgoing connections.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EXTRA_CONNECTION
Key into an Intent's extras data that points to a
Connection object. |
static java.lang.String |
EXTRA_DEVICE
Key into an Intent's extras data that points to a
Device object. |
Modifier and Type | Method and Description |
---|---|
abstract Connection |
connect(java.util.Map<java.lang.String,java.lang.String> inParameters,
ConnectionListener inListener)
Creates a new connection to the Twilio application specified in the capability token of the Device.
|
abstract void |
disconnectAll()
Disconnects all current connections associated with this Device.
|
abstract java.util.Map<Device.Capability,java.lang.Object> |
getCapabilities()
Current capabilities of the Device.
|
abstract java.lang.String |
getCapabilityToken()
Retrieves the capability token originally passed to
Twilio.createDevice(String, DeviceListener) . |
abstract Device.State |
getState()
Retrieves the current state of the device.
|
abstract boolean |
isDisconnectSoundEnabled()
Return whether a sound should be played when a connection is disconnected either normally or due to an error.
|
abstract boolean |
isIncomingSoundEnabled()
Return whether a sound should be played for an incoming connection.
|
abstract boolean |
isOutgoingSoundEnabled()
Return whether a sound should be played for an outgoing connection.
|
abstract void |
listen()
Start listening for incoming connections.
|
abstract void |
release()
Shuts down and releases the
Device . |
abstract void |
setDeviceListener(DeviceListener inListener)
Sets a new
DeviceListener object to respond to device events. |
abstract void |
setDisconnectSoundEnabled(boolean enabled)
Set whether a sound should be played when a connection is disconnected either normally or due to an error.
|
abstract void |
setIncomingIntent(android.app.PendingIntent inIntent)
Sets a
PendingIntent that will be sent when an incoming connection is received. |
abstract void |
setIncomingSoundEnabled(boolean enabled)
Set whether a sound should be played for an incoming connection.
|
abstract void |
setOutgoingSoundEnabled(boolean enabled)
Set whether a sound should be played for an outgoing connection.
|
abstract void |
unlisten()
Stop listening for incoming connections.
|
abstract void |
updateCapabilityToken(java.lang.String inCapabilityToken)
Updates the capabilities of the Device.
|
public static final java.lang.String EXTRA_DEVICE
Device
object.public static final java.lang.String EXTRA_CONNECTION
Connection
object.public abstract void release()
Device
.
Since you can't be certain of when the garbage collector will run,
this will terminate all connections and release resources immediately.public abstract void listen()
Twilio.createDevice(String, DeviceListener)
or updateCapabilityToken(String)
if the token allows.
This method only needs to be called if unlisten()
was previously called.unlisten()
public abstract void unlisten()
unlisten()
or because the Device has not been granted the incoming capability.listen()
public abstract java.lang.String getCapabilityToken()
Twilio.createDevice(String, DeviceListener)
.public abstract void updateCapabilityToken(java.lang.String inCapabilityToken)
Device.State.OFFLINE
because the capabilities have expired.
In these cases, the capabilities will need to be updated.
If the device is currently listening for incoming connections, it will restart the listening process
(if permitted) using these updated capabilities.
Existing connections are not affected by updating the capability token.inCapabilityToken
- The new capability token string.Twilio.createDevice(String, DeviceListener)
public abstract Connection connect(java.util.Map<java.lang.String,java.lang.String> inParameters, ConnectionListener inListener)
inParameters
- An optional Map containing parameters for the outgoing connection that get
passed to your Twilio Application. These parameters are merged with any parameters
supplied in the Capability Token.
If there are any key collisions with the two Maps, the value(s) from
the @{link Device.Capability.APPLICATION_PARAMETERS
Map will take precedence.inListener
- A ConnectionListener
delegate object to respond to connection eventsConnection
handle, or null if the connection could not be createdpublic abstract void disconnectAll()
public abstract java.util.Map<Device.Capability,java.lang.Object> getCapabilities()
Device.Capability
enum.public abstract Device.State getState()
Device.State
enum valueDevice.State
public abstract void setDeviceListener(DeviceListener inListener)
DeviceListener
object to respond to device events.inListener
- A DeviceListener
, or nullpublic abstract void setIncomingIntent(android.app.PendingIntent inIntent)
PendingIntent
that will be sent when an incoming connection is received.
The PendingIntent passed may be a reference to an Activity, Service, or
BroadcastReceiver. When your component receives the intent, you should
choose to accept, ignore, or reject the new connection.
When the Intent is received in your application, you can retrieve the
Device
and Connection
objects related to the incoming connection
by looking in the extras contained within the intent, using the keys
EXTRA_DEVICE
and EXTRA_CONNECTION
, which both
implement the Parcelable interface.
When this occurs, you should assign an appropriate ConnectionListener
on
the Connection
to properly respond to events.
Pending incoming connections may be received at any time, including while another
connection is active. This intent will be invoked once for each connection, and your
code should handle this situation appropriately. A single pending connection can be
accepted as long as no other connections are active; all other currently pending incoming
connections will be automatically rejected by the library until the active connection is terminated.inIntent
- A PendingIntent to call when an incoming connecion is receivedEXTRA_DEVICE
,
EXTRA_CONNECTION
,
Connection.accept()
,
Connection.ignore()
,
Connection.reject()
public abstract void setIncomingSoundEnabled(boolean enabled)
isIncomingSoundEnabled()
is true
.
See the Twilio Client Android Getting Started guide for more
information on sounds.enabled
- true
to enable, false
to disablepublic abstract boolean isIncomingSoundEnabled()
true
. See the Twilio Client Android
Getting Started guide for more information on sounds.public abstract void setOutgoingSoundEnabled(boolean enabled)
isOutgoingSoundEnabled()
is true
.
See the Twilio Client Android Getting Started guide for more information
on sounds.enabled
- true
to enable, false
to disablepublic abstract boolean isOutgoingSoundEnabled()
true
. See the Twilio Client Android
Getting Started guide for more information on sounds.public abstract void setDisconnectSoundEnabled(boolean enabled)
isDisconnectSoundEnabled()
is true
.
See the Twilio Client Android Getting Started guide for more
information on sounds.enabled
- true
to enable, false
to disablepublic abstract boolean isDisconnectSoundEnabled()
true
. See the Twilio Client Android Getting Started guide for more information on sounds.