在Android应用程序中啜饮集成

时间:2013-10-05 08:15:09

标签: android sip

我正在使用Android中提供的原生Sip库开发一个应用程序。这是我的代码

 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();
        }

    }

但是当我打电话时,我会在日志中打印出行

我收到此错误:

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

我不熟悉它没有找到问题。我也有一些类似的库 LIB FOR INTEGRATING SIP IN ANDROID PROVIDED BY SIPDROID

仍然没有正确的文档如何使用这个库。任何一种帮助都会很明显。

1 个答案:

答案 0 :(得分:3)

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

第二个参数peer uri需要是一个有效的SIP uri,如:

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