What’s cool about Callbase is allowing businesses manage their calls right there on the browser. Just a sign up; available anywhere; no installs. But what about extending this flexibility to mobile devices? What about giving agents the flexibility of receiving and making calls on their mobile device anywhere, anytime? Since Callbase is built on SIP, platform portability should be an easy one. The Android platform is one I have been working on for some days now.
The Android SIP stack
Android provides a high level SIP API from versions 2.3 (Gingerbread) and above. The implementation is straight forward:
Initialize the SipManager
Build the local Sip profile
Start the manager with a pending intent for incoming calls
Send registration requests
So here is our SipDemo class
It is that straight forward. In less than an hour, you can build a simple client that can make and receive calls. To receive calls, you just register a broadcast receiver for the pending intent you registered earlier.
So in our SipDemo class,
And here, the broadcast receiver:
Making calls is as well easy. You don’t need to build a dialer to get started with. For something quick, you can simply intercept calls from the phone’s dialer (the beauty of Android). Just register for the NEW_OUTGOING_CALL intent in your manifest
Here is our broadcast receiver:
…and back to our SipDemo class
That’s as easy as it can get. You will find more interesting methods to end, mute, hold and all that in the SipAudioCall class. The only other things you have to take care of are normal manifest permissions and class clean up (unregistering broadcast receivers, closing the manager).
Manifest permissions and feature requests:
Cleaning up, once our [SipDemo] activity is done:
Even though the specs states the SIP API is available for Android devices from 2.3, it is not. The Android SIP API is not supported on all devices. Interestingly, it is supported on my old 2.3 LG P970 and not my 4.4 Moto G. (By the way, you have to test on real device and not the Android emulator).
We can do a simple test. The SipManager class has some methods to test device support.
In most cases, the API will be supported but not VOIP. And that is a big bummer there. This makes the Android SIP API limiting if you are planning to build something targeted at different devices.
Finding an alternative
With the Android SIP API out, what are the alternatives? Well, there are a couple of open source SIP stacks for Android. The popular ones people talk about are:
Now another problem - choosing. After a full day of experimenting and digging, I finally settled for Doubango. But why Doubango? Two reasons:
High level API
Some of the stacks offer only low level APIs. They require you to have a good knowledge of the SIP protocol. Nothing is handed to you on a platter of gold. You must know what headers, what messages, what requests to send at the right time. There is nothing like calling a simple register() method to help you handle SIP server registration.
Doubango offers a high level API that makes SIP development a lot easier and faster.
Doubango has an Android library that can be integrated easily. All the hard C/Android JNI integration already done.
Setting up Doubango
The journey starts from downloading the Android NGN stack from code.google.com/p/imsdroid/. (The core project is available at code.google.com/p/doubango/source/checkout). There is a PDF (android-ngn-stack-00.pdf) in /branch/2.0 that explains the library setup - importing to Eclipse and creating your project. Once that is done, you can start building.
For me, the PDF documentation didn’t help much as regards development. I had to figure a lot of things by experimenting. The sample source codes and imsdroid source were also helpful.
Building on the [high level] API
The implementation is similar to that of Android SIP API
Start the ‘library engine’ and SIP service
Set configuration details
Register call state and registration state broadcast receivers
Send registration request
Let’s start with the initializing the engine and SIP service and registering the broadcast receivers.
Here are the receivers:
Before we can send a registeration request, we need to set necessary SIP configuration details. The NGN stack has a configuration utility for this.
The configuration service is persistent. This means you only have to set this values once - say the first time the user logs in. If this has been done (doesn’t matter what activity or when), then you can send the registration request.
So how do we make calls? Simple. Create an outgoing call session. For the sake of this post, we will do the same thing we did earlier with Android SIP API - intercept calls from the phone’s dialer
You will want to start a new activity (let’s call it MakeCallActivity) in that broadcast that will show the user the necessary action buttons (at least an “End call” button) and interact call state with the user. You should also find a way to pass call state from the CallStateReceiver (shown earlier) to this MakeCallActivity. What I did was send call state broadcasts from CallStateReceiver and create listeners within my MakeCallActivity (and ReceiveCallActivity). This will enable you know call states within calls and how to update the UI as necessary.
Receiving calls is just as easy. Remember our CallStateReceiver? Just start a new activity (let’s call it ReceiveCallActivity) to handle incoming calls in the incoming call state.
It is interesting to see and experiment with the many possibilities of SIP on Android. Doubango may not be the perfect library for you. If you are a core SIP developer, you may want to consider the low level APIs like JAIN and MjSIP.
I have been using the Callbase for Android app (alpha) to make and receive calls on my Moto G. (I don’t have a SIM. I created a personal organisation and purchased a US number on Callbase). It works ok but still needs some face lift here and there. Once the app is ok for public use, we will release for beta.
My name is Opeyemi Obembe. I build things for web and mobile and write about my experiments. Follow me on Twitter–@kehers.