0

我正在使用 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,用于在 SIPDROID 提供的 ANDROID 中集成 SIP

仍然没有正确的文档如何使用这个库。任何形式的帮助都是可观的。

4

1 回答 1

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

第二个参数 peer uri 必须是有效的 SIP uri,例如:

sip:<username>@<server>:<port>
于 2013-10-08T12:24:37.433 回答