错误:当我想在Android中启动新的SIP会话时,“无法创建SipSession;网络不可用”

时间:2015-06-24 08:09:38

标签: java android android-studio sip

我想与Android进行SIP通话。我知道连接没问题。我在X-Lite中测试过它。但是createSipSession()不会执行。这是错误:

  

创建SipSession失败;网络不可用?

这是我的代码:

public SipManager mSipManager = null;
public SipProfile mSipProfile = null;
public SipAudioCall mCall = null;


public void onbtnLoginClicked(View v) {

    // Create SIP Manager
    if (mSipManager == null) {
        mSipManager = SipManager.newInstance(this);
    }

    // Find EditText controls
    EditText txtId = (EditText) findViewById(R.id.txtId);
    EditText txtUsername = (EditText) findViewById(R.id.txtUsername);
    EditText txtPassword = (EditText) findViewById(R.id.txtPassword);
    TextView lblError = (TextView) findViewById(R.id.lblError);

    lblError.setText("No Errors Yet");

    String id = txtId.getText().toString();
    String username = txtUsername.getText().toString();
    String password = txtPassword.getText().toString();

    try {

        SipProfile.Builder builder = new SipProfile.Builder(username,id);
        SipProfile.Builder builder = new SipProfile.Builder("sip:rostamiani@sip2sip.info");
        builder.setPassword(password);
        mSipProfile = builder.build();
    } catch (java.text.ParseException e) {
        e.printStackTrace();
    }
}

public void onbtnCallClicked(View v) {

    TextView lblError = (TextView) findViewById(R.id.lblError);
    lblError.setText("No Errors Yet");

    try {
        mCall = mSipManager.makeAudioCall(mSipProfile.getUriString(),"sip:3333@sip2sip.info",null,20);
        SipAudioCall.Listener mCallListener = new SipAudioCall.Listener();  // <---Error
    }
    catch (SipException e) {
        Log.e("SipService", e.getMessage());
        lblError.setText(e.getMessage());
    }

}

1 个答案:

答案 0 :(得分:0)

在我的情况下,解决方案是更改sip帐户,因为它不支持我的国家,其次我在登录后立即添加了“睡眠时间”(10秒,但可能是5)。

Thread.sleep(10000);