Java Android SipManager:Android.net.sip.SipException:SipService.createSession()返回null

Java Android SipManager:Android.net.sip.SipException:SipService.createSession()返回null,java,android,sip,Java,Android,Sip,所以,我已经使用Androids Sip库编写了一段时间的Android Sip应用程序,但是我无法让注册工作正常进行。当前,当我调用SipManager.register():android.net.sip.SipException:SipService.createSession()返回null,它会给我以下错误 我的代码: public static void Register(final String username, final String password, final Stri

所以,我已经使用Androids Sip库编写了一段时间的Android Sip应用程序,但是我无法让注册工作正常进行。当前,当我调用
SipManager.register()
android.net.sip.SipException:SipService.createSession()返回null
,它会给我以下错误

我的代码:

public static void Register(final String username, final String password, final String domain, final String cbf)
        throws ParseException, SipException {

    Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register");
    /*
     * Luodaan SIP-profiili
     */
    SipProfile.Builder builder = new SipProfile.Builder(username, domain);
    builder.setPassword(password);
    //builder.setProtocol("TCP");
    //builder.setPort(5060);
    builder.setAutoRegistration(false);
    _sipprofile = builder.build();

    Intent intent = new Intent();
    intent.setAction("android.jahtipuhelin.INCOMING_CALL");
    PendingIntent pendingIntent = PendingIntent.getBroadcast(_context, 0, intent, Intent.FILL_IN_DATA);
    _sipmanager.open(_sipprofile, pendingIntent, new SipRegistrationListener() {
        @Override
        public void onRegistering(String s) {
            Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 0");

        }

        @Override
        public void onRegistrationDone(String s, long l) {
            Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 1");

            try {
                _sipmanager.register(_sipprofile, 30, null);
                _sipmanager.setRegistrationListener(_sipprofile.getUriString(),  new JPSipRegistrationListener(_class, cbf));
            } catch (SipException e) {
                Log.e(MainActivity.LOGTAG,e.getClass().toString()+ ": "+ e.getMessage());
                e.printStackTrace();
            }
        }

        @Override
        public void onRegistrationFailed(String s, int i, String s2) {
            Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 2");
            Log.d(MainActivity.LOGTAG, s2);

            try {

                _sipmanager.register(_sipprofile, 30, null);
                _sipmanager.setRegistrationListener(_sipprofile.getUriString(),  new JPSipRegistrationListener(_class, cbf));
            } catch (SipException e) {
                Log.e(MainActivity.LOGTAG,e.getClass().toString()+ ": "+ e.getMessage());
                e.printStackTrace();
            }
        }
    });//*/

    Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - 2");
}


private static class JPSipRegistrationListener implements SipRegistrationListener {
    private MainActivity _parent;
    private String _callBack;

    public JPSipRegistrationListener(MainActivity ma, String callBack) {
        this._parent = ma;
        this._callBack = callBack;
    }

    @Override
    public void onRegistering(String localProfileUri) {
        Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistering");
        _parent.callSub(_callBack, REGISTERING, 0, "");
    }

    @Override
    public void onRegistrationDone(String localProfileUri, long expiryTime) {
        Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistrationDone");

        _parent.callSub(_callBack, REGISTRATION_DONE, 0, "");
    }

    @Override
    public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
        Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistrationFailed");

        Log.e(MainActivity.LOGTAG, "Virhe Sip-rekisteröinnissä: "+errorCode+": "+errorMessage);
        if (errorCode == -10) {
            return;
        }
        _parent.callSub(_callBack, REGISTRATION_FAILED, errorCode, errorMessage);
    }

}
运行时,将产生以下输出:

08-11 18:50:58.276  24449-24449/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register
08-11 18:50:58.436  24449-24465/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register - testi 2
08-11 18:50:58.436  24449-24465/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: registration not running
08-11 18:50:58.446  24449-24449/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register - 2
08-11 18:50:58.666  24449-24465/fi.hieta.aatu.android.jahtipuhelin E/fi.hieta.aatu.android.jahtipuhelin: class android.net.sip.SipException: SipService.createSession() returns null

有人知道我做错了什么吗?另外,我尝试手动注册sip配置文件,而不是使用自动注册。(顺便说一句,我的第一个问题是关于stackoverflow,所以请温和一点:)

更新:使用该解决方案,例外情况消失了,但我无法接到任何电话

我刚刚找到了解决办法。您必须先呼叫open,然后再呼叫register。 此外,不要使用open(SipDemo说是这样,不知道为什么)的侦听器,而是在注册后注册它(对我来说是有效的)

所以我的代码是:

manager.open(localProfile, pendingIntent, null);

manager.register(localProfile, 20, listener);

manager.setRegistrationListener(localProfile.getUriString(), listener);

似乎至少还有另一个怪癖导致了相同的错误代码。如果您的手机上有一个具有相同请求URI的预定义帐户,那么您尝试在应用程序中创建的第二个帐户将以这种方式失败。请注意,即使未为传入呼叫设置该帐户(=后端中的SIP寄存器),也会发生这种情况。
我希望Android团队能够修复这个错误,或者至少抛出一个有意义的错误。

你正在尝试使用移动数据连接进行注册吗?????使用wifiI进行尝试不需要setRegistrationListener,它在Android 4.4.4上的Nexus 4上工作-但是在同样运行Android 4.4.4的Nexus 5上,我仍然得到SipService.createSession()返回null。