FileDocCategorySizeDatePackage
SipManager.javaAPI DocAndroid 5.1 API25361Thu Mar 12 22:22:52 GMT 2015android.net.sip

SipManager

public class SipManager extends Object
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 {@link #newInstance newInstance()}.

The APIs in this class allows you to:

  • Create a {@link SipSession} to get ready for making calls or listen for incoming calls. See {@link #createSipSession createSipSession()} and {@link #getSessionFor getSessionFor()}.
  • Initiate and receive generic SIP calls or audio-only SIP calls. Generic SIP calls may be video, audio, or other, and are initiated with {@link #open open()}. Audio-only SIP calls should be handled with a {@link SipAudioCall}, which you can acquire with {@link #makeAudioCall makeAudioCall()} and {@link #takeAudioCall takeAudioCall()}.
  • Register and unregister with a SIP service provider, with {@link #register register()} and {@link #unregister unregister()}.
  • Verify session connectivity, with {@link #isOpened isOpened()} and {@link #isRegistered isRegistered()}.

Note: Not all Android-powered devices support VOIP calls using SIP. You should always call {@link android.net.sip.SipManager#isVoipSupported isVoipSupported()} to verify that the device supports VOIP calling and {@link android.net.sip.SipManager#isApiSupported isApiSupported()} to verify that the device supports the SIP APIs. Your application must also request the {@link android.Manifest.permission#INTERNET} and {@link android.Manifest.permission#USE_SIP} permissions.

Developer Guides

For more information about using SIP, read the Session Initiation Protocol developer guide.

Fields Summary
public static final int
INCOMING_CALL_RESULT_CODE
The result code to be sent back with the incoming call {@link PendingIntent}.
public static final String
EXTRA_CALL_ID
Key to retrieve the call ID from an incoming call intent.
public static final String
EXTRA_OFFER_SD
Key to retrieve the offered session description from an incoming call intent.
public static final String
ACTION_SIP_SERVICE_UP
Action to broadcast when SipService is up. Internal use only.
public static final String
ACTION_SIP_INCOMING_CALL
Action string for the incoming call intent for the Phone app. Internal use only.
public static final String
ACTION_SIP_ADD_PHONE
Action string for the add-phone intent. Internal use only.
public static final String
ACTION_SIP_REMOVE_PHONE
Action string for the remove-phone intent. Internal use only.
public static final String
ACTION_SIP_CALL_OPTION_CHANGED
Action string for the SIP call option configuration changed intent. This is used to communicate change to the SIP call option, triggering re-registration of the SIP phone accounts. Internal use only.
public static final String
EXTRA_LOCAL_URI
Part of the ACTION_SIP_ADD_PHONE and ACTION_SIP_REMOVE_PHONE intents. Internal use only.
private static final String
TAG
private ISipService
mSipService
private android.content.Context
mContext
Constructors Summary
private SipManager(android.content.Context context)

        mContext = context;
        createSipService();
    
Methods Summary
public voidclose(java.lang.String localProfileUri)
Closes the specified profile to not make/receive calls. All the resources that were allocated to the profile are also released.

param
localProfileUri the URI of the profile to close
throws
SipException if calling the SIP service results in an error

        try {
            mSipService.close(localProfileUri);
        } catch (RemoteException e) {
            throw new SipException("close()", e);
        }
    
public static android.content.IntentcreateIncomingCallBroadcast(java.lang.String callId, java.lang.String sessionDescription)
Creates an incoming call broadcast intent.

param
callId the call ID of the incoming call
param
sessionDescription the session description of the incoming call
return
the incoming call intent
hide

        Intent intent = new Intent();
        intent.putExtra(EXTRA_CALL_ID, callId);
        intent.putExtra(EXTRA_OFFER_SD, sessionDescription);
        return intent;
    
private static ISipSessionListenercreateRelay(SipRegistrationListener listener, java.lang.String uri)

        return ((listener == null) ? null : new ListenerRelay(listener, uri));
    
private voidcreateSipService()

        IBinder b = ServiceManager.getService(Context.SIP_SERVICE);
        mSipService = ISipService.Stub.asInterface(b);
    
public SipSessioncreateSipSession(SipProfile localProfile, SipSession.Listener listener)
Creates a {@link SipSession} with the specified profile. Use other methods, if applicable, instead of interacting with {@link SipSession} directly.

param
localProfile the SIP profile the session is associated with
param
listener to listen to SIP session events

        try {
            ISipSession s = mSipService.createSession(localProfile, null);
            if (s == null) {
                throw new SipException(
                        "Failed to create SipSession; network unavailable?");
            }
            return new SipSession(s, listener);
        } catch (RemoteException e) {
            throw new SipException("createSipSession()", e);
        }
    
public static java.lang.StringgetCallId(android.content.Intent incomingCallIntent)
Gets the call ID from the specified incoming call broadcast intent.

param
incomingCallIntent the incoming call broadcast intent
return
the call ID or null if the intent does not contain it

        return incomingCallIntent.getStringExtra(EXTRA_CALL_ID);
    
public SipProfile[]getListOfProfiles()
Gets the list of profiles hosted by the SIP service. The user information (username, password and display name) are crossed out.

hide

        try {
            return mSipService.getListOfProfiles();
        } catch (RemoteException e) {
            return new SipProfile[0];
        }
    
public static java.lang.StringgetOfferSessionDescription(android.content.Intent incomingCallIntent)
Gets the offer session description from the specified incoming call broadcast intent.

param
incomingCallIntent the incoming call broadcast intent
return
the offer session description or null if the intent does not have it

        return incomingCallIntent.getStringExtra(EXTRA_OFFER_SD);
    
public SipSessiongetSessionFor(android.content.Intent incomingCallIntent)
Gets the {@link SipSession} that handles the incoming call. For audio calls, consider to use {@link SipAudioCall} to handle the incoming call. See {@link #takeAudioCall}. Note that the method may be called only once for the same intent. For subsequent calls on the same intent, the method returns null.

param
incomingCallIntent the incoming call broadcast intent
return
the session object that handles the incoming call

        try {
            String callId = getCallId(incomingCallIntent);
            ISipSession s = mSipService.getPendingSession(callId);
            return ((s == null) ? null : new SipSession(s));
        } catch (RemoteException e) {
            throw new SipException("getSessionFor()", e);
        }
    
public static booleanisApiSupported(android.content.Context context)
Returns true if the SIP API is supported by the system.

        return context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_SIP);
    
public static booleanisIncomingCallIntent(android.content.Intent intent)
Checks if the intent is an incoming call broadcast intent.

param
intent the intent in question
return
true if the intent is an incoming call broadcast intent

        if (intent == null) return false;
        String callId = getCallId(intent);
        String offerSd = getOfferSessionDescription(intent);
        return ((callId != null) && (offerSd != null));
    
public booleanisOpened(java.lang.String localProfileUri)
Checks if the specified profile is opened in the SIP service for making and/or receiving calls.

param
localProfileUri the URI of the profile in question
return
true if the profile is enabled to receive calls
throws
SipException if calling the SIP service results in an error

        try {
            return mSipService.isOpened(localProfileUri);
        } catch (RemoteException e) {
            throw new SipException("isOpened()", e);
        }
    
public booleanisRegistered(java.lang.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 ({@link #isOpened}).

param
localProfileUri the URI of the profile in question
return
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

        try {
            return mSipService.isRegistered(localProfileUri);
        } catch (RemoteException e) {
            throw new SipException("isRegistered()", e);
        }
    
public static booleanisSipWifiOnly(android.content.Context context)
Returns true if SIP is only available on WIFI.

        return context.getResources().getBoolean(
                com.android.internal.R.bool.config_sip_wifi_only);
    
public static booleanisVoipSupported(android.content.Context context)
Returns true if the system supports SIP-based VOIP API.

        return context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_SIP_VOIP) && isApiSupported(context);
    
public SipAudioCallmakeAudioCall(SipProfile localProfile, SipProfile peerProfile, SipAudioCall.Listener listener, int timeout)
Creates a {@link SipAudioCall} to make a call. The attempt will be timed out if the call is not established within {@code timeout} seconds and {@link SipAudioCall.Listener#onError onError(SipAudioCall, SipErrorCode.TIME_OUT, String)} will be called.

param
localProfile the SIP profile to make the call from
param
peerProfile the SIP profile to make the call to
param
listener to listen to the call events from {@link SipAudioCall}; can be null
param
timeout the timeout value in seconds. Default value (defined by SIP protocol) is used if {@code timeout} is zero or negative.
return
a {@link SipAudioCall} object
throws
SipException if calling the SIP service results in an error or VOIP API is not supported by the device
see
SipAudioCall.Listener#onError
see
#isVoipSupported

        if (!isVoipSupported(mContext)) {
            throw new SipException("VOIP API is not supported");
        }
        SipAudioCall call = new SipAudioCall(mContext, localProfile);
        call.setListener(listener);
        SipSession s = createSipSession(localProfile, null);
        call.makeCall(peerProfile, s, timeout);
        return call;
    
public SipAudioCallmakeAudioCall(java.lang.String localProfileUri, java.lang.String peerProfileUri, SipAudioCall.Listener listener, int timeout)
Creates a {@link SipAudioCall} to make an audio call. The attempt will be timed out if the call is not established within {@code timeout} seconds and {@link SipAudioCall.Listener#onError onError(SipAudioCall, SipErrorCode.TIME_OUT, String)} will be called.

param
localProfileUri URI of the SIP profile to make the call from
param
peerProfileUri URI of the SIP profile to make the call to
param
listener to listen to the call events from {@link SipAudioCall}; can be null
param
timeout the timeout value in seconds. Default value (defined by SIP protocol) is used if {@code timeout} is zero or negative.
return
a {@link SipAudioCall} object
throws
SipException if calling the SIP service results in an error or VOIP API is not supported by the device
see
SipAudioCall.Listener#onError
see
#isVoipSupported

        if (!isVoipSupported(mContext)) {
            throw new SipException("VOIP API is not supported");
        }
        try {
            return makeAudioCall(
                    new SipProfile.Builder(localProfileUri).build(),
                    new SipProfile.Builder(peerProfileUri).build(), listener,
                    timeout);
        } catch (ParseException e) {
            throw new SipException("build SipProfile", e);
        }
    
public static android.net.sip.SipManagernewInstance(android.content.Context context)
Creates a manager instance. Returns null if SIP API is not supported.

param
context application context for creating the manager object
return
the manager instance or null if SIP API is not supported


                                          
         
        return (isApiSupported(context) ? new SipManager(context) : null);
    
public voidopen(SipProfile localProfile)
Opens the profile for making generic SIP calls. The caller may make subsequent calls through {@link #makeAudioCall}. If one also wants to receive calls on the profile, use {@link #open(SipProfile, PendingIntent, SipRegistrationListener)} instead.

param
localProfile the SIP profile to make calls from
throws
SipException if the profile contains incorrect settings or calling the SIP service results in an error

        try {
            mSipService.open(localProfile);
        } catch (RemoteException e) {
            throw new SipException("open()", e);
        }
    
public voidopen(SipProfile localProfile, android.app.PendingIntent incomingCallPendingIntent, SipRegistrationListener listener)
Opens the profile for making calls and/or receiving generic SIP calls. The caller may make subsequent calls through {@link #makeAudioCall}. 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 {@link #getCallId} and {@link #getOfferSessionDescription} to retrieve those extras.

param
localProfile the SIP profile to receive incoming calls for
param
incomingCallPendingIntent When an incoming call is received, the SIP service will call {@link PendingIntent#send(Context, int, Intent)} to send back the intent to the caller with {@link #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.
param
listener to listen to registration events; can be null
see
#getCallId
see
#getOfferSessionDescription
see
#takeAudioCall
throws
NullPointerException if {@code incomingCallPendingIntent} is null
throws
SipException if the profile contains incorrect settings or calling the SIP service results in an error
see
#isIncomingCallIntent
see
#getCallId
see
#getOfferSessionDescription

        if (incomingCallPendingIntent == null) {
            throw new NullPointerException(
                    "incomingCallPendingIntent cannot be null");
        }
        try {
            mSipService.open3(localProfile, incomingCallPendingIntent,
                    createRelay(listener, localProfile.getUriString()));
        } catch (RemoteException e) {
            throw new SipException("open()", e);
        }
    
public voidregister(SipProfile localProfile, int expiryTime, SipRegistrationListener listener)
Manually registers the profile to the corresponding SIP provider for receiving calls. {@link #open(SipProfile, PendingIntent, SipRegistrationListener)} is still needed to be called at least once in order for the SIP service to notify the caller with the {@link android.app.PendingIntent} when an incoming call is received.

param
localProfile the SIP profile to register with
param
expiryTime registration expiration time (in seconds)
param
listener to listen to the registration events
throws
SipException if calling the SIP service results in an error

        try {
            ISipSession session = mSipService.createSession(localProfile,
                    createRelay(listener, localProfile.getUriString()));
            if (session == null) {
                throw new SipException(
                        "SipService.createSession() returns null");
            }
            session.register(expiryTime);
        } catch (RemoteException e) {
            throw new SipException("register()", e);
        }
    
public voidsetRegistrationListener(java.lang.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 {@link #open(SipProfile, PendingIntent, SipRegistrationListener)}).

param
localProfileUri the URI of the profile
param
listener to listen to registration events; can be null
throws
SipException if calling the SIP service results in an error

        try {
            mSipService.setRegistrationListener(
                    localProfileUri, createRelay(listener, localProfileUri));
        } catch (RemoteException e) {
            throw new SipException("setRegistrationListener()", e);
        }
    
public SipAudioCalltakeAudioCall(android.content.Intent incomingCallIntent, SipAudioCall.Listener listener)
Creates a {@link SipAudioCall} to take an incoming call. Before the call is returned, the listener will receive a {@link SipAudioCall.Listener#onRinging} callback.

param
incomingCallIntent the incoming call broadcast intent
param
listener to listen to the call events from {@link SipAudioCall}; can be null
return
a {@link SipAudioCall} object
throws
SipException if calling the SIP service results in an error

        if (incomingCallIntent == null) {
            throw new SipException("Cannot retrieve session with null intent");
        }

        String callId = getCallId(incomingCallIntent);
        if (callId == null) {
            throw new SipException("Call ID missing in incoming call intent");
        }

        String offerSd = getOfferSessionDescription(incomingCallIntent);
        if (offerSd == null) {
            throw new SipException("Session description missing in incoming "
                    + "call intent");
        }

        try {
            ISipSession session = mSipService.getPendingSession(callId);
            if (session == null) {
                throw new SipException("No pending session for the call");
            }
            SipAudioCall call = new SipAudioCall(
                    mContext, session.getLocalProfile());
            call.attachCall(new SipSession(session), offerSd);
            call.setListener(listener);
            return call;
        } catch (Throwable t) {
            throw new SipException("takeAudioCall()", t);
        }
    
public voidunregister(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.

param
localProfile the SIP profile to register with
param
listener to listen to the registration events
throws
SipException if calling the SIP service results in an error

        try {
            ISipSession session = mSipService.createSession(localProfile,
                    createRelay(listener, localProfile.getUriString()));
            if (session == null) {
                throw new SipException(
                        "SipService.createSession() returns null");
            }
            session.unregister();
        } catch (RemoteException e) {
            throw new SipException("unregister()", e);
        }