Linphone核心监听器没有接收来电

时间:2018-04-25 13:45:27

标签: android voip sip-server

我试图用linphone sdk添加sip来电,注册成功,我可以看到正在进行的通话,并且通话状态按预期记录,但我无法接听来电。我正在使用意向服务来处理连接。

这是我的代码:

protected void onHandleIntent(Intent intent) {
        String sipAddress = intent.getStringExtra("address");
        String password = intent.getStringExtra("password");
        final LinphoneCoreFactory lcFactory = LinphoneCoreFactory.instance();

        // First instantiate the core Linphone object given only a listener.
        // The listener will react to events in Linphone core.
        try {
            lc = lcFactory.createLinphoneCore(new LinphoneCoreListenerBase() {
                @Override
                public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) {
                    super.callState(lc, call, state, message);
                    Log.i(TAG, "callState: ");
                }
            }, getApplication());
        } catch (LinphoneCoreException e) {
            e.printStackTrace();
        }
        lc.setUserAgent("Test app", "1.0");

        try {
            LinphoneAddress address = lcFactory.createLinphoneAddress(sipAddress);
            String username = address.getUserName();
            String domain = address.getDomain();
            if (password != null) {
                lc.addAuthInfo(lcFactory.createAuthInfo(username, password, null, domain));
            }
            // create proxy config
            LinphoneProxyConfig proxyCfg = lc.createProxyConfig(sipAddress, domain, null, true);
            proxyCfg.setExpires(2000);
            lc.addProxyConfig(proxyCfg); // add it to linphone
            lc.setDefaultProxyConfig(proxyCfg);


            running = true;
            while (running) {
                lc.iterate(); // first iterate initiates registration
                sleep(20);
            }
        } catch (LinphoneCoreException e) {
            e.printStackTrace();
        }
    }

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:0)

正如IntentService文档(https://developer.android.com/reference/android/app/IntentService)所述:

  

根据需要启动服务,使用工作线程依次处理每个Intent,并在失去工作时自行停止。

我认为你不应该把监听器放在IntentService中。相反,将它放在一个长期运行的服务中,以便听众可以实际上留在那里接收事件。