在android上注册两次SIP



我试图在android上编写一个简单的SIP应用程序。我使用安卓API 19和使用星号作为SIP服务器。然而,我发现每次执行SipManager.open()时,它都会注册两次。当我打电话时,有两个频道在呼叫。

我的代码如下:

                Intent intent = new Intent();
                intent.setAction(ACTION_INCOMING_CALL);
                PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
                if (mSipManager == null) {
                    mSipManager = SipManager.newInstance(this);
                }
                SipProfile.Builder builder = new SipProfile.Builder("<some sip id>", SIP_SERVER);
                builder.setPassword("<sip password>");
                mSipProfile = builder.build();
                mSipManager.close(mSipProfile.getUriString());
                mSipManager.open(mSipProfile, pendingIntent, null);
                mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {
                    public void onRegistering(String localProfileUri) {
                        updateStatus("Registering");
                        Log.d("SipActivity", "Registering with SIP Server...");
                    }
                    public void onRegistrationDone(String localProfileUri, long expiryTime) {
                        updateStatus("Ready");
                        Log.d("SipActivity", "Ready");
                    }
                    public void onRegistrationFailed(String localProfileUri, int errorCode,
                        String errorMessage) {
                        updateStatus("Registration failed." + errorCode + " >>>" + errorMessage);
                        Log.d("SipActivity", "Registration failed.  Please check settings." + errorMessage);
                    }
                });

我放了日志,以确保我打开了一次,但日志显示两次"向SIP服务器注册"和两次"准备就绪"。

我找到了它注册两次的原因。在我将expiryTime记录在onRegistrationDone上之后,第一个事件是-1,这意味着会话已经过期。所以,由于autoRegister标志为true,它将再次注册。

最新更新