SIP stands for (Session Initiation Protocol). It is a protocol that let applications easily set up outgoing and incoming voice calls, without having to manage sessions, transport-level communication, or audio record or playback directly.
Applications
Some of the common applications of SIP are.
Video conferencing
Instant messaging
Requirements
Here are the requirements for developing a SIP application −
Android OS must be 2.3 or higher
You must have a data connection or WIFI
You must have an SIP account in order to use this service.
SIP Classes
Here is a summary of the classes that are included in the Android SIP API:
Sr.No
Class & description
1
Handles an Internet audio call over SIP
Defines error codes returned during SIP actions
Provides APIs for SIP tasks, such as initiating SIP connections, and provides access to related SIP services
Defines a SIP profile, including a SIP account, domain and server information
Represents a SIP session that is associated with a SIP dialog or a standalone transaction not within a dialog
Functions of SIP
SIP has following major functions.
SIP allows for the establishment of user location
SIP provides a mechanism for call management
SIP provides feature negotiation, so that all the parties in the call can agree to the features supported among them
Components of SIP
SIP has two major components which are listed below.
User Agent Client (UAC)
User Agent Server (UAS)
UAC or User Agent Client are those end users who generates requests and send those requests to the server.These requests are generated by the client applications running on their systems.
UAS or User Agent Server are those systems which get the request generated by UAC. The UAS process those requests and then according to the requests it generates responses accordingly.
SipManager
SipManager is an android API 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 SipManager has many functions for managing SIP tasks. Some of the functions are listed below.
Sr.No
Class & description
1
Closes the specified profile to not make/receive calls
Gets the call ID from the specified incoming call broadcast intent
Checks if the specified profile is opened in the SIP service for making and/or receiving calls
Returns true if SIP is only available on WIFI
Checks if the SIP service has successfully registered the profile to the SIP provider (specified in the profile) for receiving calls
Returns true if the system supports SIP-based VOIP API
Manually unregisters the profile from the corresponding SIP provider for stop receiving further calls
Источник
SipDemo — SIP Demo
This is a demo application highlighting how to make internet-based calls with the SIP API. The application uses a walkie-talkie style interface, allowing you to only be heard when the button is pushed down.
The source code for this demo app shows how to accomplish three key things with SIP: Make a call, receive a call, and signal to the Android platform that your app wants to receive incoming SIP calls, so that they can be handled from within the application.
The application includes:
SipSettings — a PreferenceActivity that supplies basic settings for SIP authentication.
IncomingCallReceiver — a BroadcastReceiver that listens for incoming SIP calls and passes them to WalkieTalkieActivity for handling.
WalkieTalkieActivity — a activity that login to SIP provider and registers the device to receive incoming SIP, handles incoming calls and makes outgoing calls, managing UI during the call.
If you are developing an application that uses the SIP API, remember that the feature is supported only on Android 2.3 (API level 9) and higher versions of the platform. Also, among devices running Android 2.3 (API level 9) or higher, not all devices will offer SIP support. To ensure that your application can only be installed on devices that are capable of supporting SIP, remember to add the following to the application’s manifest before publishing to Android Market:
, which indicates to Android Market and the platform that your application requires Android 2.3 or higher. For more information, see API Levels and the documentation for the element.
To control how Android Market filters your application from devices that do not support SIP, remember to add the following to the application’s manifest
, which tells Android Market that your application uses the SIP API. The declaration should include an android:required attribute that indicates whether you want Android Market to filter the application from devices that do not offer SIP support. Other declarations may also be needed, depending on your implementation. For more information, see the documentation for the element.
Источник
SIP on Android
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:
The problem
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.
Platform ready 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.
In conclusion
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.
Источник
Android sip api example
NOTICE! This project is experimental, so don’t use it in production! No support is provided and only bug fixes and pull requests can be accepted.
What you need to work with this library:
An android device with Android API 18+ (4.3.3 or higher)
A PBX (E.g. VoiSmart Orchestra NG or FreeSWITCH, which is open). I’m not going to enter in the detail of how to properly configure your PBX, because that’s a different topic and there are excellent tutorials out there.
This project wraps the standard PJSUA2 bindings in a background service and completely hides SIP from the rest of the application, to be able to have VoIP capabilities at a high level of abstraction. You can talk to the service using static methods and you will receive broadcast intents as a response. To talk to the service, refer to SipServiceCommand static methods. To receive events from the service, extend BroadcastEventReceiver. To see which events are emitted by the service, refer to BroadcastEventEmitter. All the commands that you will send to the service will get executed in the background and without blocking your main thread. Once the service has done the requested job or operation, it will notify you with a broadcast intent. So, you don’t risk blocking your UI thread in any way.
Native PJSIP library for Android is compiled using PJSIP Android Builder
State of the art
What is tested and working:
Single account
Make a single call
In-Call operations
mute
unmute
hold
un-hold
blind transfer
Attended call transfer
send DTMF (RFC 2833)
Accept an incoming call
Answer with video an incoming call
Decline an incoming call
Get/Set codec priorities
Hang up all active calls
Hold all active calls
Hold/Decline sip call when incoming/outgoing gsm call
Video support
switch camera
mute/unmute video
video preview
Use of a fixed SIP Call-ID Header . Refer to this for more details
Get Call Statistics on call disconnected
Sip Credential encryption on device. Refer to VoiSmart Crypto library for more details
Call Reconnection: useful after a network disconnection, it will try to reconnect the call with new ip/port
What is missing (contributions are welcome):
Multiple calls support
be able to handle other calls coming in while you have an active call
be able to hold the current call and make another one (this is the base for attended transfers and conference calls)
Conference calls
Complete multiple accounts support
Respond to a call and play a sound file
Support for In-Call RTCP signaling to get call statistics
Other things which I’m not aware at the moment.
Used Libraries versions
PJSIP: 2.11
OpenSSL: 1.1.1k
OpenH264: 2.1.0
Opus: 1.3.1
bcg729: 1.1.1
This library ships with a default logger which logs with the default Android Log class and a default DEBUG loglevel. You can customize such behaviour by either: