android - SIP在android上注册两次

标签 android android-intent sip

我尝试在 android 上编写一个简单的 SIP 应用程序。我正在使用 android API 19 并使用星号作为 SIP 服务器。但是我发现每次执行 SipManager.open() 时,它都会注册两次。当我打电话时,两个 channel 都在呼唤。

我的代码如下:

                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 服务器注册”和两次“就绪”。

最佳答案

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

关于android - SIP在android上注册两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26524288/

相关文章:

android - 在 Android OpenGL ES 中放大纹理?

java - 从 Android 应用程序启动两个 Activity

sip - ISIM 和 USIM 有什么区别?

java - sipFactory.setPathName ("gov.nist");运行时错误

android - activityForResult 按钮返回时的 WebView 不起作用

使用 android 的 sip 进行 Android 音频通话

android - Dagger 2,底部导航和注入(inject)

android - 选择共享菜单时如何从浏览器获取html代码

android - 从进度对话框中删除白色背景

Android: Intent 通过通知传递给 Activity ......我没有在 Intent 中获得正确的额外内容