Android net.sip:manager.makeAudioCall(..)抛出sip会话错误

时间:2013-01-26 20:44:53

标签: android sip

我正在尝试在Android上使用sip建立通话。我的清单中的权限是:

<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.USE_SIP"/>
<uses-permission android:name="android.permission.INTERNET"/>

CALL_PHONE权限在那里,因为我的应用程序也调用常规号码。
这是活动代码:

package x.x.x;

import java.text.ParseException;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.sip.SipAudioCall;
import android.net.sip.SipException;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.os.Bundle;
import android.util.Log;

public class CallScreen extends Activity{
public SipManager manager = null;
public SipProfile me = null;
public SipAudioCall call = null;
//IncomingCallReceiver callReceiver;
String domain = "myserver.net";
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.callscreen);

    initManager();
    Log.d("Z:","Done initManger()");
    Thread waiter = new Thread(){
        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
                sleep(10000);
                Log.d("Z:","Done waiting");
                initCall();
                Log.d("Z:","Done initCall");
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    waiter.start();

    //initCall();

}
public void initManager()
{
    manager = SipManager.newInstance(this);
    initLocalProfile();
}
public void initLocalProfile()
{
    String username = "user";
    String password = "12345";
    String domain = "myserver.net";
    try {
        SipProfile.Builder builder = new SipProfile.Builder(username,domain);
        builder.setPassword(password);
        me = builder.build();
        //Intent intent = new Intent(); 
        //PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
        //manager.open(me,pi,null);
        manager.open(me);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
public void initCall()
{
    SipAudioCall.Listener listener = new SipAudioCall.Listener(){
        @Override
        public void onCallEstablished(SipAudioCall call) {
            // TODO Auto-generated method stub
            //super.onCallEstablished(call);
            call.startAudio();
            call.setSpeakerMode(true);
            call.toggleMute();
        }
        @Override
        public void onCallEnded(SipAudioCall call) {
            // TODO Auto-generated method stub
            super.onCallEnded(call);
        }
    };
    try {
        call = manager.makeAudioCall(me.getUriString(), "12345678910", listener, 30);
    } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

logcat上显示的错误:

01-26 22:20:25.710: D/SipAudioCall(31060): sip session error: CLIENT_ERROR: libcore.io.ErrnoException: getaddrinfo failed: ENOENT (No such file or directory)

我试图让这个小例子工作之前我组织这个代码有点不同(例如,用户名和传递不是硬编码)。我对啜饮也不是很熟悉。真的适合任何建议。
有任何想法吗?谢谢!

1 个答案:

答案 0 :(得分:8)

问题出在以下几行:

call = manager.makeAudioCall(me.getUriString(), "12345678910", listener, 30);

makeAudioCall方法must be the URI of the SIP profile to make the call to的第二个参数,但您只提供了其用户名(即:“12345678910”)。将其更改为:

call = manager.makeAudioCall(me.getUriString(), "sip:12345678910@myserver.net", listener, 30);