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

Android集成Linphone SDK连接本地PBX时出现IO错误求助

Linphone SDK集成后本地PBX SIP登录报IO错误问题

集成依赖

项目中已成功集成Linphone SDK,依赖如下:

implementation 'org.linphone:linphone-sdk-android:5.1.59'
// Adding this dependency allows the linphone-sdk to automatically handle audio focus
implementation 'androidx.media:media:1.6.0'

问题现象

使用Linphone官方提供的凭证时,所有功能正常;但切换为本地PBX的SIP凭证登录时,抛出io error错误。
已在Linphone Android官方APP中测试过该本地网络的凭证,可正常注册登录,但自研APP中无法成功。

登录功能实现代码

fun login(domain: String, username: String, password: String) {
    val mgr: ConnectivityManager =
        getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

    val listAddress: MutableList<String> = ArrayList()
    mgr.getLinkProperties(mgr.activeNetwork)?.let{network->
        network.dnsServers.forEach {
            it.hostAddress?.let { it1 -> listAddress.add(it1) }
        }
    }

    core.setDnsServers(listAddress.map { it }.toTypedArray())

    val authInfo =
        Factory.instance().createAuthInfo(username, null, password, null, null, domain, null)

    val params = core.createAccountParams()
    val senderUri = "sip:$username@$domain"

    val identity = Factory.instance().createAddress(senderUri)
    params.identityAddress = identity

    val address = Factory.instance().createAddress("sip:$domain")
    address?.transport = TransportType.Tls
    params.serverAddress = address
    params.isOutboundProxyEnabled = true
    params.isRegisterEnabled = true
    val account = core.createAccount(params)

    getInstance().core.addAuthInfo(authInfo)
    getInstance().core.addAccount(account)
    getInstance().core.defaultAccount = account

    core.start()

    account.addListener { _, state, message ->
        Log.e(TAG, "login: state $state $message" )
        if ("$state" == "Failed") {
            Utils().showShortToast(getInstance(), "Registration Failed")
        } else if ("$state" == "Ok") {
            Utils().showShortToast(getInstance(), "Registration Success")
        }
    }
}

排查与解决方案

  • DNS配置问题:代码中手动替换了DNS服务器,可能导致本地PBX域名无法解析。尝试注释掉core.setDnsServers(...)代码,使用系统默认DNS重试。
  • 传输协议不匹配:当前代码强制使用TLS传输,但本地PBX可能仅支持UDP/TCP。尝试将TransportType.Tls改为TransportType.Udp或TransportType.Tcp,同时确认PBX对应端口是否开放(默认UDP 5060、TLS 5061)。
  • AuthInfo参数缺失:createAuthInfo的realm参数传了null,部分PBX要求realm与domain一致。修改为:
    val authInfo = Factory.instance().createAuthInfo(username, null, password, null, null, domain, domain)
    
  • 网络权限检查:确认AndroidManifest.xml中已添加网络权限:
    <uses-permission android:name="android.permission.INTERNET" />
    
  • 开启详细日志:添加日志开启代码,获取更具体的错误详情:
    Factory.instance().setLogLevel(LogLevel.Debug)
    

内容的提问来源于stack exchange,提问作者Hardik Arvindbhai Sojitra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 16:31:16