Android SipProfile Uri UDP端口错误 [英] Android SipProfile Uri UDP Port error

查看:134
本文介绍了Android SipProfile Uri UDP端口错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过UPD连接到我的sip服务器,我具有用户名,服务器的IP地址(域)和端口(例如9990).

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

我收到以下错误:

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

在此行: mSipManager.register(mSipProfile,300,mSipRegistrationListener);

这是我使用的代码,改编自android文档:

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

我遇到同样的错误.

如果我尝试:

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

与上述相同的错误.

如果不指定端口,我将得到以下信息:

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

注册未运行,错误代码为-4,后跟: 注册超时,错误代码= -5

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

有什么想法如何使用UPD和自定义端口注册到我的服务器?顺便说一句,我正在WiFi上测试,我已经在清单中设置了权限和所需的"uses-feature".

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.

推荐答案

事实证明,使其生效的唯一方法是使用PendingIntent,即使您不需要或不使用它也是如此.还要设置一个空监听器@open(),请参见下面的代码:

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

这篇关于Android SipProfile Uri UDP端口错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆