With the new Sip library you can make audio calls using Voip (Voice over IP) services.
Sip features were added in Android 2.3 (API level 9). Note that not all devices above Android 2.3 support Sip features.
In order to use this library you will need to set android.jar in Tools > Configure Paths to platform-9 or above.
The library includes two types of objects: Sip and SipAudioCall. Sip is the main object which manages the Sip services. Once you make a call or receive an incoming call you will get a SipAudioCall which represents the call.
In this example the Sip code is written in the main Activity. A better solution is to manage the Sip services from a Service module. Otherwise you may lose incoming calls if the Activity is not in the foreground.
The first step is to register to the server.
Sub Activity_Create(FirstTime As Boolean)
If Sip.IsInitialized = False Then
'Check if SIP and VOIP are supported.
If Sip.IsSipSupported = False OR Sip.IsVoipSupported = False Then
ToastMessageShow("SIP not supported.", True)
'Register with the VOIP service
Sip.Initialize2("SIP", "sip:firstname.lastname@example.org", "xxx")
Sub SIP_RegistrationFailed (ErrorCode As Int, ErrorMessage As String)
Log("Failed, ErrorCode=" & ErrorCode & ", Message=" & ErrorMessage)
ToastMessageShow("Registration failed.", True)
Sub SIP_RegistrationDone (ExpiryTime As Long)
Log("RegistrationDone, ExpiryTime=" & ExpiryTime)
ToastMessageShow("SIP registered sucessfully", True)
btnMakeCall.Enabled = True
Registering is done by initializing the Sip object with your account Uri and password and calling Register.
The actual registration is done in the background.
RegistrationDone event is raised when registration completes successfully (with the expiry time measured in seconds). If there is a problem then RegistrationFailed will be raised.
The error codes are available here
Now that the Sip is registered we can make audio calls.
This is done by calling Sip.MakeCall.
For example, this code calls a free directory service:
CurrentCall = Sip.MakeCall("sip:email@example.com", 30)
CurrentCall is of type SipAudioCall and it is declared in Process_Globals.
You should now wait for the CallEstablished event (or CallError if there is a problem).
CallEstablished event is raised when the other side answers the call.
'Check that we are not already in a call.
'Seems like this event can be raised by the SIP service multiple times.
If CurrentCall.IsInCall Then Return
CurrentCall.StartAudio 'Start the audio
CurrentCall.SpeakerMode = True
ToastMessageShow("Call established", True)
When the call is established we need to call StartAudio and set SpeakerMode to True in order to start talking.
As you can see in the above code, we first check if CurrentCall.IsInCall is false. It will be true after the StartAudio call. It seems that the internal Sip service raises the CallEstablished more than once for a single call. This way we make sure that our code only runs once for each call.
When there is an incoming call, the CallRinging event will be raised:
Sub SIP_CallRinging (IncomingCall As SipAudioCall)
ToastMessageShow("Ringing from: " & IncomingCall.PeerUri, True)
CurrentCall = IncomingCall
'Answers an incoming call
A SipAudioCall is passed in this event. We should hold a reference to this object. Calling AnswerCall will cause the call to be established and will raise the CallEstablished event.
See the attached example for a simple program that calls a free directory service and handles incoming calls.
In order to test it you can register to Welcome to iptel.org, the IP Telecommunications Portal | iptel.org
. I registered two accounts and then I was able to call from the computer to the device (to test the incoming calls).
The library is available here: http://www.basic4ppc.com/forum/addit...html#post73694