JAIN SIP Stack for Android

This post will help you use JAIN SIP in your android application.  Before proceeding we need to clarify the need and background for this.

Why do this?

  • Limitations of native sip stack.

The stock native android sip stack is built on top of JAIN SIP but it does not have all functionality, there is no support for IM, presence and video calls right now. Google forked SIP Stack and never really updated the SIP API that is shipped by default and used the same package names as the original JAIN SIP project. This proved to be a major hassle to developers that wanted to add SIP capabilities worldwide as they couldn’t use JAIN SIP out of the box.

An opensource implementation of the stack can be found here. It is a java based SIP stack which allows you to integrate the sip stack seamlessly in your android application without the hassle of NDK.

  • A Complete SIP Stack

JAIN SIP is a full implementation of the RFC 3261 Specification and as well as support for several SIP RFCs.

What is the issue using the existing JAIN SIP stack?

If you have tried to use the existing JAIN SIP in any android application you might have run into package name conflicts, these conflicts are resolved now and the stack is ready to be used in android.

How to use JAIN SIP in your android app

  1. Setup a new android project
  2. First step is to download the jar from here.
  3. Include the jar in your project.

    JAIN SIP Library

Registering a SIP stack in your application

Next we are going to implement this flow and register a sip stack with a server waiting for sip requests.

SIP Register flow

Step -1: Initialize the Stack

Lets start by creating a singleton class SipStackAndroid and initialize a SIP stack. This class is going to implement SipListener and corresponding methods to process SIP events.

Step -2: Send REGISTER

The following method sends a Register packet to server.

Step -3: Send authentication information

In response to the REGISTER packet, server asks for authentication information(407 error). Which will be received in processResponse() method of the class which implements SipListener. The code snippet below sends back authentication to server.

Helper classes like AccountManagerImpl can be found in JAIN-SIP examples.

Sending a SIP Message

Next up we use the stack to send a message to a peer.  Here is the flow which we have to follow

Sip Message flow

This will send a message to the server and server is going to ask for authorization which we have already covered.

A basic android sip messenger

A basic sip messenger using JAIN sip is hosted on github restcomm-android-sdk project. You can easily test it out by downloading the apk . An interesting way to test is by using the telestax’s hosted RestComm WebRTC demo .

Register as bob as described below :

webrtc register

Next run the android application and click on register

android register

Now you can send and receive messages to and from android/webrtc page

communication between android and webrtc through jain sip


What’s Next

Voice and video calling are going to be added in the example application. Sending sip messages is the humble beginning towards a SDK for Android developers which will simplify VOIP communication in applications.

The end goal is to have both and Android SIP Stack that allows native mobile application developers to tinker with low level SIP Code as well as a higher level SDK which allow Android Mobile Application Developers to integrate Communications features into their applications without knowing anything about telecommunications.

Happy coding!

Learn, Share, Code, Create!