You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linphone Core Listener无法接收来电问题排查求助

嘿,看起来你已经搞定了注册和呼出,卡在来电这块确实挺挠头的。结合你用Intent Service处理连接的情况,我给你梳理几个最可能的排查方向:

排查Linphone SDK无法接收来电的关键要点
  • 务必确认LinphoneCoreListener回调已正确绑定
    来电通知完全依赖LinphoneCore的回调接口,要是没实现onIncomingReceived方法,或者没把Listener绑定到LinphoneCore实例上,肯定收不到来电提醒。检查你的代码里有没有类似这样的逻辑:

    LinphoneCore lc = lcFactory.createLinphoneCore(new LinphoneCoreListener() {
        @Override
        public void onIncomingReceived(LinphoneCore core, LinphoneCall call) {
            // 这里处理来电逻辑,比如弹出通知、跳转通话界面
            Log.d("Linphone", "收到来电:" + call.getRemoteAddress().asStringUriOnly());
        }
        // 按需实现其他必要回调,比如onCallStateChanged追踪通话状态
    }, this);
    

    注意:Listener要在LinphoneCore初始化时就设置,而且要确保LinphoneCore实例在Service运行期间一直被持有,别被GC回收了。

  • Intent Service的生命周期是重灾区
    Intent Service在onHandleIntent执行完毕后会自动停止销毁,这意味着你的LinphoneCore实例可能跟着被回收——注册成功后Service就没了,自然没法监听来电。解决办法是把Intent Service改成Foreground Service,让系统识别到这个服务的重要性:

    1. 先在AndroidManifest里声明必要权限:
      <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
      <!-- Android 13+还需要通知权限 -->
      <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
      
    2. 在Service的onCreate或onHandleIntent里启动前台通知:
      private void startForegroundNotification() {
          NotificationChannel channel = new NotificationChannel("LINPHONE_CHANNEL", "Linphone通话服务", NotificationManager.IMPORTANCE_LOW);
          NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          manager.createNotificationChannel(channel);
      
          Notification notification = new NotificationCompat.Builder(this, "LINPHONE_CHANNEL")
                  .setContentTitle("Linphone在线")
                  .setContentText("正在监听来电")
                  .setSmallIcon(R.drawable.ic_notification)
                  .build();
      
          startForeground(1, notification);
      }
      

    这样Service就能持续运行在前台,LinphoneCore也能保持监听状态。

  • 检查设备休眠与网络限制

    • 确保APP已申请WAKE_LOCK权限,防止设备休眠时LinphoneCore无法接收网络包:
      <uses-permission android:name="android.permission.WAKE_LOCK" />
      
      初始化LinphoneCore时可以开启唤醒锁:
      lc.enableWakeLock(true);
      
    • 部分安卓厂商会限制后台APP联网(比如小米、华为的省电模式),去系统设置里给你的APP开启「后台联网权限」,关闭省电优化中的相关限制。
  • 验证SIP注册状态与NAT穿透配置
    虽然你说注册成功,但可以在onRegistrationStateChanged回调里确认状态是LinphoneRegistrationOk,确保服务器已将你的终端标记为在线。另外,很多场景下需要配置STUN/TURN解决NAT穿透问题:

    LinphoneProxyConfig cfg = lc.createProxyConfig();
    cfg.setStunServer("stun.linphone.org"); // 替换成你的STUN服务器地址
    cfg.enableStun(true);
    lc.addProxyConfig(cfg);
    

如果这些都排查过还是不行,你可以开启Linphone的调试模式(lcFactory.setDebugMode(true, "Linphone");),查看详细日志里是否有收到INVITE请求的记录——这能帮你定位是网络层没收到包,还是应用层没处理回调。

内容的提问来源于stack exchange,提问作者Sony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:23:41