首页 > 解决方案 > Linphone 核心监听器未接听来电

问题描述

我正在尝试使用 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();
        }
    }

我的代码有什么问题?

标签: androidvoipsip-server

解决方案


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

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

我认为您不应该将侦听器放在 IntentService 中。相反,将它放在一个长时间运行的服务中,以便侦听器实际上可以一直呆在那里接收事件。


推荐阅读