8

我正在尝试在 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)

我试图让这个小例子工作,然后我组织这个代码有点不同(例如,用户名和密码不是硬编码的)。我对sip也不是很熟悉。真的appriciate任何建议。
有任何想法吗?谢谢!

4

1 回答 1

8

问题出在以下行:

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

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

call = manager.makeAudioCall(me.getUriString(), "sip:12345678910@myserver.net", listener, 30);
于 2013-09-10T14:04:29.563 回答