Android SipProfile Uri UDP Port error

2019-08-08 02:22发布

I want to connect via UPD to my sip server, I have the username, the ip address of the server (domain) and the port (for example 9990).

I get the following error:

android.net.sip.SipException: SipService.createSession() returns null

At this line: mSipManager.register(mSipProfile, 300, mSipRegistrationListener);


Here's the code I'm using, adapted from android documentation:

private void startSip() {
    LogUtils.LOGE(TAG, "[startSip]");
    if (SipManager.isVoipSupported(this) && SipManager.isApiSupported(this)) {
        if (mSipManager == null) {
            mSipManager = SipManager.newInstance(this);
        }

        try {
            SipProfile.Builder builder = new SipProfile.Builder("sip:user@domainIP:9990");
            builder.setPassword("pass"); 
            builder.setProtocol("UDP"); 

            mSipProfile = builder.build();
            mSipManager.open(mSipProfile);
            mSipManager.register(mSipProfile, 300, mSipRegistrationListener);

            mSipManager.setRegistrationListener(mSipProfile.getUriString(), mSipRegistrationListener); 

        } catch (ParseException e) {
            e.printStackTrace();
        } catch (SipException e) {
            e.printStackTrace();
        }
    } else {
        Log.d(TAG, "SIP is not supported!");
    }
}

If I try setting the profile like this:

mSipProfile.Builder builder = new SipProfile.Builder("user", "domain:port");

I get the same error.

If I try:

mSipProfile.Builder builder = new SipProfile.Builder("user", "domain");
builder.setPort(9990);

The same error as above.


If I don't specify the port I will get the following:

registration not running with error code= -4 , followed by: registration timed out with error code= -5

Any ideas how to register to my server using UPD and a custom port? Btw I am testing on WiFi and I have set the permissions and the required "uses-feature" in the manifest.

1条回答
啃猪蹄的小仙女
2楼-- · 2019-08-08 02:43

It turns out that the only way to make it work is to use a PendingIntent, even if you don't need or use it. And also set a null listener @open(), see the code below:

            mSipProfile = builder.build();

            Intent i = new Intent();
            i.setAction("android.SipDemo.INCOMING_CALL");
            PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA);

            mSipManager.open(mSipProfile, pi, null);
查看更多
登录 后发表回答