public class SipAudioCall extends Object
SipManager
,
using makeAudioCall()
and takeAudioCall()
.
Note: Using this class require the
android.Manifest.permission#INTERNET
and
android.Manifest.permission#USE_SIP
permissions. In addition, startAudio()
requires the
android.Manifest.permission#RECORD_AUDIO
,
android.Manifest.permission#ACCESS_WIFI_STATE
, and
android.Manifest.permission#WAKE_LOCK
permissions; and setSpeakerMode()
requires the
android.Manifest.permission#MODIFY_AUDIO_SETTINGS
permission.
For more information about using SIP, read the Session Initiation Protocol developer guide.
Modifier and Type | Class and Description |
---|---|
static class |
SipAudioCall.Listener
Listener for events relating to a SIP call, such as when a call is being
recieved ("on ringing") or a call is outgoing ("on calling").
|
Constructor and Description |
---|
SipAudioCall(Context context,
SipProfile localProfile)
Creates a call object with the local SIP profile.
|
Modifier and Type | Method and Description |
---|---|
void |
answerCall(int timeout)
Answers a call.
|
void |
attachCall(SipSession session,
String sessionDescription)
Attaches an incoming call to this call object.
|
void |
close()
Closes this object.
|
void |
continueCall(int timeout)
Continues a call that's on hold.
|
void |
endCall()
Ends a call.
|
AudioGroup |
getAudioGroup()
Gets the
AudioGroup object which the AudioStream object
joins. |
AudioStream |
getAudioStream()
Gets the
AudioStream object used in this call. |
SipProfile |
getLocalProfile()
Gets the local SIP profile.
|
SipProfile |
getPeerProfile()
Gets the peer's SIP profile.
|
SipSession |
getSipSession()
Gets the
SipSession that carries this call. |
int |
getState()
Gets the state of the
SipSession that carries this call. |
void |
holdCall(int timeout)
Puts a call on hold.
|
boolean |
isInCall()
Checks if the call is established.
|
boolean |
isMuted()
Checks if the call is muted.
|
boolean |
isOnHold()
Checks if the call is on hold.
|
void |
makeCall(SipProfile peerProfile,
SipSession sipSession,
int timeout)
Initiates an audio call to the specified profile.
|
void |
sendDtmf(int code)
Sends a DTMF code.
|
void |
sendDtmf(int code,
Message result)
Sends a DTMF code.
|
void |
setAudioGroup(AudioGroup group)
Sets the
AudioGroup object which the AudioStream object
joins. |
void |
setListener(SipAudioCall.Listener listener)
Sets the listener to listen to the audio call events.
|
void |
setListener(SipAudioCall.Listener listener,
boolean callbackImmediately)
Sets the listener to listen to the audio call events.
|
void |
setSpeakerMode(boolean speakerMode)
Puts the device to speaker mode.
|
void |
startAudio()
Starts the audio for the established call.
|
void |
toggleMute()
Toggles mute.
|
public SipAudioCall(Context context, SipProfile localProfile)
context
- the context for accessing system services such as
ringtone, audio, WIFI etcpublic void setListener(SipAudioCall.Listener listener)
setListener(listener, false)
.listener
- to listen to the audio call events of this objectsetListener(Listener, boolean)
public void setListener(SipAudioCall.Listener listener, boolean callbackImmediately)
SipAudioCall
can only hold one listener at a time. Subsequent
calls to this method override the previous listener.listener
- to listen to the audio call events of this objectcallbackImmediately
- set to true if the caller wants to be called
back immediately on the current statepublic boolean isInCall()
public boolean isOnHold()
public void close()
public SipProfile getLocalProfile()
public SipProfile getPeerProfile()
public int getState()
SipSession
that carries this call.
The value returned must be one of the states in SipSession.State
.public SipSession getSipSession()
SipSession
that carries this call.public void attachCall(SipSession session, String sessionDescription) throws SipException
session
- the session that receives the incoming callsessionDescription
- the session description of the incoming callSipException
- if the SIP service fails to attach this object to
the session or VOIP API is not supported by the deviceSipManager.isVoipSupported(android.content.Context)
public void makeCall(SipProfile peerProfile, SipSession sipSession, int timeout) throws SipException
timeout
seconds
and onError(SipAudioCall, SipErrorCode.TIME_OUT, String)
will be called.peerProfile
- the SIP profile to make the call tosipSession
- the SipSession
for carrying out the calltimeout
- the timeout value in seconds. Default value (defined by
SIP protocol) is used if timeout
is zero or negative.SipException
- if the SIP service fails to create a session for the
call or VOIP API is not supported by the deviceSipAudioCall.Listener.onError(android.net.sip.SipAudioCall, int, java.lang.String)
,
SipManager.isVoipSupported(android.content.Context)
public void endCall() throws SipException
SipException
- if the SIP service fails to end the callpublic void holdCall(int timeout) throws SipException
SipAudioCall.Listener.onCallHeld(android.net.sip.SipAudioCall)
is
called. The attempt will be timed out if the call is not established
within timeout
seconds and
onError(SipAudioCall, SipErrorCode.TIME_OUT, String)
will be called.timeout
- the timeout value in seconds. Default value (defined by
SIP protocol) is used if timeout
is zero or negative.SipException
- if the SIP service fails to hold the callSipAudioCall.Listener.onError(android.net.sip.SipAudioCall, int, java.lang.String)
public void answerCall(int timeout) throws SipException
timeout
seconds and
onError(SipAudioCall, SipErrorCode.TIME_OUT, String)
will be called.timeout
- the timeout value in seconds. Default value (defined by
SIP protocol) is used if timeout
is zero or negative.SipException
- if the SIP service fails to answer the callSipAudioCall.Listener.onError(android.net.sip.SipAudioCall, int, java.lang.String)
public void continueCall(int timeout) throws SipException
SipAudioCall.Listener.onCallEstablished(android.net.sip.SipAudioCall)
is called. The attempt will be timed
out if the call is not established within timeout
seconds and
onError(SipAudioCall, SipErrorCode.TIME_OUT, String)
will be called.timeout
- the timeout value in seconds. Default value (defined by
SIP protocol) is used if timeout
is zero or negative.SipException
- if the SIP service fails to unhold the callSipAudioCall.Listener.onError(android.net.sip.SipAudioCall, int, java.lang.String)
public void toggleMute()
public boolean isMuted()
public void setSpeakerMode(boolean speakerMode)
Note: Requires the
android.Manifest.permission#MODIFY_AUDIO_SETTINGS
permission.
speakerMode
- set true to enable speaker mode; false to disablepublic void sendDtmf(int code)
code
- the DTMF code to send. Value 0 to 15 (inclusive) are valid
inputs.public void sendDtmf(int code, Message result)
code
- the DTMF code to send. Value 0 to 15 (inclusive) are valid
inputs.result
- the result message to send when donepublic AudioStream getAudioStream()
AudioStream
object used in this call. The object
represents the RTP stream that carries the audio data to and from the
peer. The object may not be created before the call is established. And
it is undefined after the call ends or the close()
method is
called.AudioStream
object or null if the RTP stream has not
yet been set uppublic AudioGroup getAudioGroup()
AudioGroup
object which the AudioStream
object
joins. The group object may not exist before the call is established.
Also, the AudioStream
may change its group during a call (e.g.,
after the call is held/un-held). Finally, the AudioGroup
object
returned by this method is undefined after the call ends or the
close()
method is called. If a group object is set by
setAudioGroup(AudioGroup)
, then this method returns that object.AudioGroup
object or null if the RTP stream has not
yet been set upgetAudioStream()
public void setAudioGroup(AudioGroup group)
AudioGroup
object which the AudioStream
object
joins. If audioGroup
is null, then the AudioGroup
object
will be dynamically created when needed. Note that the mode of the
AudioGroup
is not changed according to the audio settings (i.e.,
hold, mute, speaker phone) of this object. This is mainly used to merge
multiple SipAudioCall
objects to form a conference call. The
settings of the first object (that merges others) override others'.getAudioStream()
public void startAudio()
SipAudioCall.Listener.onCallEstablished(android.net.sip.SipAudioCall)
is called.
Note: Requires the
android.Manifest.permission#RECORD_AUDIO
,
android.Manifest.permission#ACCESS_WIFI_STATE
and
android.Manifest.permission#WAKE_LOCK
permissions.