Bellow我的代码是登录twilio客户端正在运行
public void login(final String clientName,
final boolean allowOutgoing,
final boolean allowIncoming) {
if (loginListener != null)
loginListener.onLoginStarted();
this.lastClientName = clientName;
this.lastAllowOutgoing = allowOutgoing;
this.lastAllowIncoming = allowIncoming;
if (!twilioSdkInited) {
if (twilioSdkInitInProgress)
return;
twilioSdkInitInProgress = true;
Twilio.setLogLevel(Log.DEBUG);
Twilio.initialize(context, new Twilio.InitListener() {
@Override
public void onInitialized() {
Log.e(TAG, "onInitialized");
twilioSdkInited = true;
twilioSdkInitInProgress = false;
obtainCapabilityToken(clientName, allowOutgoing, allowIncoming);
}
@Override
public void onError(Exception error) {
Log.e(TAG, "onInitialized onError :" + error.toString());
Log.e(TAG, " onInitialized onError : isTokenExpired is Blank");
twilioSdkInitInProgress = false;
if (loginListener != null)
loginListener.onLoginError(error);
}
@Override
protected void finalize() throws Throwable {
Log.e(TAG, "@call finalize()");
if (device != null)
device.release();
if (connection != null)
connection.disconnect();
super.finalize();
}
});
} else {
Log.e(TAG, "twilioSdkInited obtainCapabilityToken");
obtainCapabilityToken(clientName, allowOutgoing, allowIncoming);
}
重新启动我的应用时,在日志下方会产生错误。
07-06 10:10:14.265 32611-32611/com.reach.communications E/NewCallScreenActivity: @call onLoginStarted
07-06 10:10:14.265 32611-32611/com.reach.communications I/PJSIP: 10:10:14.265 sip_endpoint.c !Module "mod-pjsua-log" unregistered
07-06 10:10:14.265 32611-32611/com.reach.communications I/PJSIP: 10:10:14.265 sip_endpoint.c Module "mod-pjsua-log" registered
07-06 10:10:14.265 32611-32611/com.reach.communications E/BasicPhone: onInitialized onError :java.lang.RuntimeException: Twilio.initialize() already called
07-06 10:10:14.265 32611-32611/com.reach.communications E/BasicPhone: onInitialized onError : isTokenExpired is Blank
07-06 10:10:14.265 32611-32611/com.reach.communications E/NewCallScreenActivity: @call onLoginError :java.lang.RuntimeException: Twilio.initialize() already called
07-06 10:10:14.265 32611-32611/com.reach.communications E/NewCallScreenActivity: @Call State idle
如果我收到此错误并重新登录客户端,如何处理。或如何重新初始化twilio。
onError(异常错误)
提前致谢
答案 0 :(得分:1)
我看到你正在尝试.release()
。如果您使用.shutdown()
method会怎样?这将终止所有连接,释放所有Device对象,并释放SDK使用的所有资源。
然后,您可以在下次通话前再次安全地拨打.initialize()
。
此外,您可以使用.isInitialized()
来确定客户端是否准备就绪。
如果这些变化有任何帮助,请告诉我。