android - 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();
}
}
我的代码有什么问题?
解决方案
正如 IntentService 文档(https://developer.android.com/reference/android/app/IntentService)所述:
该服务根据需要启动,使用工作线程依次处理每个 Intent,并在工作结束时自行停止。
我认为您不应该将侦听器放在 IntentService 中。相反,将它放在一个长时间运行的服务中,以便侦听器实际上可以一直呆在那里接收事件。
推荐阅读
- css - 允许绝对元素的自动宽度大于父元素
- sql-server - 更新自引用列
- c++ - 无法使 std::reference_wrapper 与 std::unique_ptr 一起使用
- redis - Redis 会失败。Ubuntu 18.04
- azure - Sonarqube 的 AEM 规则不支持 Java 1.8
- python - 将嵌套 JSON 中的逗号分隔字符串转换为 Python 列表
- regex - 混合数据集 Google Data Studio (Google Analytics + WordPress)
- r - 从 R 数据表中删除名称为“NA”的列和行
- google-visualization - Angular Google Charts 中的导出到 CSV 功能
- c++ - 尝试从文件中读取对象并在正确获取一些记录后我的程序检测到 eof,留下了许多记录