Android SipProfile Uri UDP Port error

断了今生、忘了曾经 提交于 2020-01-06 02:52:29

问题


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:


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);


来源:https://stackoverflow.com/questions/24077623/android-sipprofile-uri-udp-port-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!