Sneha Bansal
Sneha Bansal

Reputation: 941

Sip integration in android application

I am developing an app using native Sip library available in android . Here is my code

 package com.example.demosip;
    import java.text.ParseException;
    import android.net.sip.SipAudioCall;
    import android.net.sip.SipException;
    import android.net.sip.SipManager;
    import android.net.sip.SipProfile;
    import android.net.sip.SipRegistrationListener;
    import android.os.Bundle;
    import android.os.CountDownTimer;
    import android.app.Activity;
    import android.app.PendingIntent;
    import android.content.Intent;
    import android.util.Log;
    import android.view.Menu;

    public class CopyOfSipMainActivty2 extends Activity {
        SipManager sipM;
        SipProfile sipP;
        SipProfile.Builder builder;
        SipAudioCall.Listener listener;

        @
        Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_sip_main_activty);
            if (sipM == null) {
                sipM = SipManager.newInstance(this);
                try {
                    builder = new SipProfile.Builder("ABC", "123.123.123.1");
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                builder.setPassword("ABC");
                builder.setPort(5060);
                sipP = builder.build();

                //register 
                Intent intent = new Intent();
                intent.setAction("android.SipDemo.INCOMING_CALL");
                PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,         intent, Intent.FILL_IN_DATA);
                try {
                    sipM.open(sipP, pendingIntent, null);
                } catch (SipException e) {      
                    e.printStackTrace();
                }
            }
        }@
        Override
        protected void onStart() {
            // TODO Auto-generated method stub
            super.onStart();
        }@
        Override
        protected void onResume() {
            // TODO Auto-generated method stub
            try {
                sipM.setRegistrationListener(sipP.getUriString(), new SipRegistrationListener() {
                    @
                    Override
                    public void onRegistrationFailed(String localProfileUri, int errorCode,
                        String errorMessage) {
                        Log.e("registration failed", "registration failed");
                        // TODO Auto-generated method stub
                    }@
                    Override
                    public void onRegistrationDone(String localProfileUri, long expiryTime) {
                        // TODO Auto-generated method stub
                        Log.e("registration done", "registration done");
                    }@
                    Override
                    public void onRegistering(String localProfileUri) {
                        // TODO Auto-generated method stub
                        Log.e("registring", "registring");
                    }
                });

                listener = new SipAudioCall.Listener() {
                    @
                    Override
                    public void onCallEstablished(SipAudioCall call) {
                        Log.e("inside listener ", "call established");
                        call.startAudio();
                        call.setSpeakerMode(true);
                        call.toggleMute();
                    }@
                    Override
                    public void onCallEnded(SipAudioCall call) {
                        Log.e("inside listener ", "call ended");
                        // Do something.
                    }
                };
            } catch (SipException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            new CountDownTimer(5 * 1000, 1000) {
                @
                Override
                public void onTick(long millisUntilFinished) {
                    Log.e("on tick", "on tick ");
                }
                @
                Override
                public void onFinish() {
                    try {
                        Log.e("on finish", "calling nummber");
                        sipM.makeAudioCall(sipP.getUriString(), "91 XXXXXXXXXX", listener, 1000 * 20);
                    } catch (SipException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }.start();

            super.onResume();
        }

    }

But as I make call I get line printed in log

I am getting this error:

sip session error: CLIENT_ERROR: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
10-05 11:33:14.660: D/SipAudioCall(6864): stop audiocall

As I am new to it not findind the problem .I have also got some libs like LIB FOR INTEGRATING SIP IN ANDROID PROVIDED BY SIPDROID

still not have proper docs how to use this library .Any kind of help will be appreciable.

Upvotes: 0

Views: 1618

Answers (1)

radical
radical

Reputation: 4424

sipM.makeAudioCall(sipP.getUriString(), "91 XXXXXXXXXX", listener, 1000 * 20);

The second argument, peer uri, needs to be a valid SIP uri, like:

sip:<username>@<server>:<port>

Upvotes: 3

Related Questions