SipManager
public
class
SipManager
extends Object
java.lang.Object | |
↳ | android.net.sip.SipManager |
This class was deprecated
in API level 31.
SipManager
and associated classes are no longer supported and
should not be used as the basis of future VOIP apps.
Provides APIs for SIP tasks, such as initiating SIP connections, and provides access to related
SIP services. This class is the starting point for any SIP actions. You can acquire an instance
of it with newInstance()
.
The APIs in this class allows you to:
- Create a
SipSession
to get ready for making calls or listen for incoming calls. SeecreateSipSession()
andgetSessionFor()
. - Initiate and receive generic SIP calls or audio-only SIP calls. Generic SIP calls may
be video, audio, or other, and are initiated with
open()
. Audio-only SIP calls should be handled with aSipAudioCall
, which you can acquire withmakeAudioCall()
andtakeAudioCall()
. - Register and unregister with a SIP service provider, with
register()
andunregister()
. - Verify session connectivity, with
isOpened()
andisRegistered()
.
Note: Not all Android-powered devices support VOIP calls using
SIP. You should always call isVoipSupported()
to verify that the device supports VOIP calling and isApiSupported()
to verify that the device supports
the SIP APIs. Your application must also request the Manifest.permission.INTERNET
and Manifest.permission.USE_SIP
permissions.
Developer Guides
For more information about using SIP, read the Session Initiation Protocol developer guide.
Summary
Constants | |
---|---|
String |
EXTRA_CALL_ID
Key to retrieve the call ID from an incoming call intent. |
String |
EXTRA_OFFER_SD
Key to retrieve the offered session description from an incoming call intent. |
int |
INCOMING_CALL_RESULT_CODE
The result code to be sent back with the incoming call
|
Public methods | |
---|---|
void
|
close(String localProfileUri)
Closes the specified profile to not make/receive calls. |
SipSession
|
createSipSession(SipProfile localProfile, SipSession.Listener listener)
Creates a |
static
String
|
getCallId(Intent incomingCallIntent)
Gets the call ID from the specified incoming call broadcast intent. |
static
String
|
getOfferSessionDescription(Intent incomingCallIntent)
Gets the offer session description from the specified incoming call broadcast intent. |
SipSession
|
getSessionFor(Intent incomingCallIntent)
Gets the |
static
boolean
|
isApiSupported(Context context)
Returns true if the SIP API is supported by the system. |
static
boolean
|
isIncomingCallIntent(Intent intent)
Checks if the intent is an incoming call broadcast intent. |
boolean
|
isOpened(String localProfileUri)
Checks if the specified profile is opened in the SIP service for making and/or receiving calls. |
boolean
|
isRegistered(String localProfileUri)
Checks if the SIP service has successfully registered the profile to the SIP provider (specified in the profile) for receiving calls. |
static
boolean
|
isSipWifiOnly(Context context)
Returns true if SIP is only available on WIFI. |
static
boolean
|
isVoipSupported(Context context)
Returns true if the system supports SIP-based VOIP API. |
SipAudioCall
|
makeAudioCall(String localProfileUri, String peerProfileUri, SipAudioCall.Listener listener, int timeout)
Creates a |
SipAudioCall
|
makeAudioCall(SipProfile localProfile, SipProfile peerProfile, SipAudioCall.Listener listener, int timeout)
Creates a |
static
SipManager
|
newInstance(Context context)
Creates a manager instance. |
void
|
open(SipProfile localProfile, PendingIntent incomingCallPendingIntent, SipRegistrationListener listener)
Opens the profile for making calls and/or receiving generic SIP calls. |
void
|
open(SipProfile localProfile)
Opens the profile for making generic SIP calls. |
void
|
register(SipProfile localProfile, int expiryTime, SipRegistrationListener listener)
Manually registers the profile to the corresponding SIP provider for receiving calls. |
void
|
setRegistrationListener(String localProfileUri, SipRegistrationListener listener)
Sets the listener to listen to registration events. |
SipAudioCall
|
takeAudioCall(Intent incomingCallIntent, SipAudioCall.Listener listener)
Creates a |
void
|
unregister(SipProfile localProfile, SipRegistrationListener listener)
Manually unregisters the profile from the corresponding SIP provider for stop receiving further calls. |
Inherited methods | |
---|---|
Constants
EXTRA_CALL_ID
public static final String EXTRA_CALL_ID
Key to retrieve the call ID from an incoming call intent.
Constant Value: "android:sipCallID"
EXTRA_OFFER_SD
public static final String EXTRA_OFFER_SD
Key to retrieve the offered session description from an incoming call intent.
Constant Value: "android:sipOfferSD"
INCOMING_CALL_RESULT_CODE
public static final int INCOMING_CALL_RESULT_CODE
The result code to be sent back with the incoming call
PendingIntent
.
Constant Value: 101 (0x00000065)
Public methods
close
public void close (String localProfileUri)
Closes the specified profile to not make/receive calls. All the resources that were allocated to the profile are also released.
Parameters | |
---|---|
localProfileUri |
String : the URI of the profile to close |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error |
createSipSession
public SipSession createSipSession (SipProfile localProfile, SipSession.Listener listener)
Creates a SipSession
with the specified profile. Use other
methods, if applicable, instead of interacting with SipSession
directly.
Parameters | |
---|---|
localProfile |
SipProfile : the SIP profile the session is associated with |
listener |
SipSession.Listener : to listen to SIP session events |
Returns | |
---|---|
SipSession |
Throws | |
---|---|
SipException |
getCallId
public static String getCallId (Intent incomingCallIntent)
Gets the call ID from the specified incoming call broadcast intent.
Parameters | |
---|---|
incomingCallIntent |
Intent : the incoming call broadcast intent |
Returns | |
---|---|
String |
the call ID or null if the intent does not contain it |
getOfferSessionDescription
public static String getOfferSessionDescription (Intent incomingCallIntent)
Gets the offer session description from the specified incoming call broadcast intent.
Parameters | |
---|---|
incomingCallIntent |
Intent : the incoming call broadcast intent |
Returns | |
---|---|
String |
the offer session description or null if the intent does not have it |
getSessionFor
public SipSession getSessionFor (Intent incomingCallIntent)
Gets the SipSession
that handles the incoming call. For audio
calls, consider to use SipAudioCall
to handle the incoming call.
See takeAudioCall(Intent, Listener)
. Note that the method may be called only once
for the same intent. For subsequent calls on the same intent, the method
returns null.
Parameters | |
---|---|
incomingCallIntent |
Intent : the incoming call broadcast intent |
Returns | |
---|---|
SipSession |
the session object that handles the incoming call |
Throws | |
---|---|
SipException |
isApiSupported
public static boolean isApiSupported (Context context)
Returns true if the SIP API is supported by the system.
Parameters | |
---|---|
context |
Context |
Returns | |
---|---|
boolean |
isIncomingCallIntent
public static boolean isIncomingCallIntent (Intent intent)
Checks if the intent is an incoming call broadcast intent.
Parameters | |
---|---|
intent |
Intent : the intent in question |
Returns | |
---|---|
boolean |
true if the intent is an incoming call broadcast intent |
isOpened
public boolean isOpened (String localProfileUri)
Checks if the specified profile is opened in the SIP service for making and/or receiving calls.
Parameters | |
---|---|
localProfileUri |
String : the URI of the profile in question |
Returns | |
---|---|
boolean |
true if the profile is enabled to receive calls |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error |
isRegistered
public boolean isRegistered (String localProfileUri)
Checks if the SIP service has successfully registered the profile to the
SIP provider (specified in the profile) for receiving calls. Returning
true from this method also implies the profile is opened
(isOpened(String)
).
Parameters | |
---|---|
localProfileUri |
String : the URI of the profile in question |
Returns | |
---|---|
boolean |
true if the profile is registered to the SIP provider; false if the profile has not been opened in the SIP service or the SIP service has not yet successfully registered the profile to the SIP provider |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error |
isSipWifiOnly
public static boolean isSipWifiOnly (Context context)
Returns true if SIP is only available on WIFI.
Parameters | |
---|---|
context |
Context |
Returns | |
---|---|
boolean |
isVoipSupported
public static boolean isVoipSupported (Context context)
Returns true if the system supports SIP-based VOIP API.
Parameters | |
---|---|
context |
Context |
Returns | |
---|---|
boolean |
makeAudioCall
public SipAudioCall makeAudioCall (String localProfileUri, String peerProfileUri, SipAudioCall.Listener listener, int timeout)
Creates a SipAudioCall
to make an audio call. 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.
Parameters | |
---|---|
localProfileUri |
String : URI of the SIP profile to make the call from |
peerProfileUri |
String : URI of the SIP profile to make the call to |
listener |
SipAudioCall.Listener : to listen to the call events from SipAudioCall ;
can be null |
timeout |
int : the timeout value in seconds. Default value (defined by
SIP protocol) is used if timeout is zero or negative. |
Returns | |
---|---|
SipAudioCall |
a SipAudioCall object |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error or VOIP API is not supported by the device |
makeAudioCall
public SipAudioCall makeAudioCall (SipProfile localProfile, SipProfile peerProfile, SipAudioCall.Listener listener, int timeout)
Creates a SipAudioCall
to make a call. 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.
Parameters | |
---|---|
localProfile |
SipProfile : the SIP profile to make the call from |
peerProfile |
SipProfile : the SIP profile to make the call to |
listener |
SipAudioCall.Listener : to listen to the call events from SipAudioCall ;
can be null |
timeout |
int : the timeout value in seconds. Default value (defined by
SIP protocol) is used if timeout is zero or negative. |
Returns | |
---|---|
SipAudioCall |
a SipAudioCall object |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error or VOIP API is not supported by the device |
newInstance
public static SipManager newInstance (Context context)
Creates a manager instance. Returns null if SIP API is not supported.
Parameters | |
---|---|
context |
Context : application context for creating the manager object |
Returns | |
---|---|
SipManager |
the manager instance or null if SIP API is not supported |
open
public void open (SipProfile localProfile, PendingIntent incomingCallPendingIntent, SipRegistrationListener listener)
Opens the profile for making calls and/or receiving generic SIP calls. The caller may
make subsequent calls through makeAudioCall(SipProfile, SipProfile, Listener, int)
. If the
auto-registration option is enabled in the profile, the SIP service
will register the profile to the corresponding SIP provider periodically
in order to receive calls from the provider. When the SIP service
receives a new call, it will send out an intent with the provided action
string. The intent contains a call ID extra and an offer session
description string extra. Use getCallId(Intent)
and
getOfferSessionDescription(Intent)
to retrieve those extras.
Parameters | |
---|---|
localProfile |
SipProfile : the SIP profile to receive incoming calls for |
incomingCallPendingIntent |
PendingIntent : When an incoming call is received, the
SIP service will call
PendingIntent.send(Context, int, Intent) to send back the
intent to the caller with INCOMING_CALL_RESULT_CODE as the
result code and the intent to fill in the call ID and session
description information. It cannot be null. |
listener |
SipRegistrationListener : to listen to registration events; can be null |
Throws | |
---|---|
NullPointerException |
if incomingCallPendingIntent is null |
SipException |
if the profile contains incorrect settings or calling the SIP service results in an error |
open
public void open (SipProfile localProfile)
Opens the profile for making generic SIP calls. The caller may make subsequent calls
through makeAudioCall(SipProfile, SipProfile, Listener, int)
. If one also wants to receive calls on the
profile, use
open(android.net.sip.SipProfile, android.app.PendingIntent, android.net.sip.SipRegistrationListener)
instead.
Parameters | |
---|---|
localProfile |
SipProfile : the SIP profile to make calls from |
Throws | |
---|---|
SipException |
if the profile contains incorrect settings or calling the SIP service results in an error |
register
public void register (SipProfile localProfile, int expiryTime, SipRegistrationListener listener)
Manually registers the profile to the corresponding SIP provider for
receiving calls.
open(android.net.sip.SipProfile, android.app.PendingIntent, android.net.sip.SipRegistrationListener)
is
still needed to be called at least once in order for the SIP service to
notify the caller with the PendingIntent
when an incoming call is
received.
Parameters | |
---|---|
localProfile |
SipProfile : the SIP profile to register with |
expiryTime |
int : registration expiration time (in seconds) |
listener |
SipRegistrationListener : to listen to the registration events |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error |
setRegistrationListener
public void setRegistrationListener (String localProfileUri, SipRegistrationListener listener)
Sets the listener to listen to registration events. No effect if the
profile has not been opened to receive calls (see
open(android.net.sip.SipProfile, android.app.PendingIntent, android.net.sip.SipRegistrationListener)
).
Parameters | |
---|---|
localProfileUri |
String : the URI of the profile |
listener |
SipRegistrationListener : to listen to registration events; can be null |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error |
takeAudioCall
public SipAudioCall takeAudioCall (Intent incomingCallIntent, SipAudioCall.Listener listener)
Creates a SipAudioCall
to take an incoming call. Before the call
is returned, the listener will receive a
SipAudioCall.Listener.onRinging
callback.
Parameters | |
---|---|
incomingCallIntent |
Intent : the incoming call broadcast intent |
listener |
SipAudioCall.Listener : to listen to the call events from SipAudioCall ;
can be null |
Returns | |
---|---|
SipAudioCall |
a SipAudioCall object |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error |
unregister
public void unregister (SipProfile localProfile, SipRegistrationListener listener)
Manually unregisters the profile from the corresponding SIP provider for stop receiving further calls. This may interference with the auto registration process in the SIP service if the auto-registration option in the profile is enabled.
Parameters | |
---|---|
localProfile |
SipProfile : the SIP profile to register with |
listener |
SipRegistrationListener : to listen to the registration events |
Throws | |
---|---|
SipException |
if calling the SIP service results in an error |