Android 创建SipSession失败;网络不可用,只有重新启动才有帮助
我正在开发一个简单的应用程序,允许用户使用sip协议发起呼叫。 问题是在某些情况下无法创建SipSession(例如,删除具有活动sip会话的应用程序,然后重新安装) 在这种情况下,我得到一个错误:Android 创建SipSession失败;网络不可用,只有重新启动才有帮助,android,sip,Android,Sip,我正在开发一个简单的应用程序,允许用户使用sip协议发起呼叫。 问题是在某些情况下无法创建SipSession(例如,删除具有活动sip会话的应用程序,然后重新安装) 在这种情况下,我得到一个错误: android.net.sip.SipException: Failed to create SipSession; network unavailable? 而且它只有在物理设备重新启动后才能工作 我的Sip课程: public class SipDataManager { private C
android.net.sip.SipException: Failed to create SipSession; network unavailable?
而且它只有在物理设备重新启动后才能工作
我的Sip课程:
public class SipDataManager {
private Context context;
private SipManager sipManager;
private SipProfile sipProfile;
private SipSession sipSession;
private UserProfile userProfile;
public SipDataManager(Context context, UserProfile userProfile) {
this.context = context;
this.userProfile = userProfile;
}
public void initialize() throws SipException {
Log.d("mylog", "initialize manager");
if (sipManager == null) {
Log.d("mylog", "sip manager is not null");
sipManager = SipManager.newInstance(context);
}
initializeProfile();
}
private void initializeProfile() throws SipException {
if (sipManager == null)
return;
if (sipProfile != null) {
close();
}
sipProfile = userProfile.build();
Intent intent = new Intent();
intent.setAction("ru.tenet.sipclient.INCOMING_CALL");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, Intent.FILL_IN_DATA);
sipManager.open(sipProfile, pendingIntent, null);
sipSession = sipManager.createSipSession(sipProfile, new MySipSessionListener());
sipManager.setRegistrationListener(sipProfile.getUriString(), new MySipRegistrationListener());
}
public void close() {
try {
if (sipProfile != null) {
sipManager.close(sipProfile.getUriString());
}
} catch (Exception ee) {
Log.e("mylog", "Failed to close local profile.", ee);
}
}
//getters and setters
我试着把这个拿走
sipSession = sipManager.createSipSession(sipProfile, new MySipSessionListener());
在这种情况下,我不会得到任何异常,但SipRegistrationListener回调不会得到调用
只有重新启动才有帮助
有人面临这个问题吗?我没有找到任何正确的解决办法
解决方案
问题出在我的设备或固件上(三星Galaxy s4,Android 5.0.1官方版,但一些集成应用程序被root删除)。
已在三星Galaxy s4上检查,Android 4.3.1带有氰-没问题。在尝试打开发送或接收呼叫的配置文件之前创建SipSession
sipSession = sipManager.createSipSession(sipProfile, new MySipSessionListener());
sipManager.open(sipProfile, pendingIntent, null);
我也有同样的问题,无法通过编程来纠正它。当前的解决方案是添加一个10秒的延迟处理程序,以检查OnRegistrationDone和OnRegistrating事件是否在此期间触发。以下代码紧靠initializeLocalProfile函数中的manager.setRegistrationListener方法。当检测到此错误情况时,将启动SIP首选项活动,并向用户通知SIP库错误,请求他们重新启动设备。同一处理程序还检测连接到已定义SIP服务器时出现的问题,并向用户发出服务器未找到通知。这两种错误情况通常都会触发“注册超时”错误,但在该事件中无法区分这两种错误类型,超时需要30秒
if (!manager.isOpened(me.getUriString())) {
if (me_listener == null) {
manager.open(me, pi, null);
} else {
manager.open(me, pi, me_listener);
}
}
// This listener must be added AFTER manager.open is called,
// Otherwise the methods aren't guaranteed to fire.
if (me_listener == null) {
bConnecting = true;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (sentConnecting == false && bLocalOpen == false) { //never connected or connecting
updateStatus("SIP Library Error");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = prefs.edit();
editor.remove("namePref");
editor.remove("domainPref");
editor.putString("statusPref", "SIP Library Error - Please Restart Device and Try Again");
editor.commit();
updatePreferences();
return;
} else if (bConnecting == true && bLocalOpen == false) { //never connected
updateStatus("Server Not Found");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = prefs.edit();
editor.remove("namePref");
editor.remove("domainPref");
editor.putString("statusPref", "Server Not Found, Please Edit and Try Again");
editor.commit();
updatePreferences();
return;
}
}
}, 10000);
获取
android.net.sip.SipException:无法创建SipSession;网络不可用?
在此sipSession=sipManager.createSipSession(sipProfile,new myipsessionlistener())上代码>我开始认为android SipManager中存在bug。实际上,我不需要SipSession对象,而是用它来解释问题;您确定您的sip服务器工作正常吗?如果我在其中放置了无效的sip主机,则可能会产生该错误。您是否尝试使用WireShark或tcpdump捕获sip注册?是的,sip工作正常,我可以拨打电话(已检查)。但如果我的sip连接被中断(例如重新安装应用程序),那么我就无法从MySipRegistrationListener()
获得回调。没什么。SIP服务器上没有注册数据包。。。但在设备重启后,我可以看到服务器上的注册数据包……听起来你们已经超越了应用程序的问题。应用程序重新安装应销毁应用程序级别的所有内容。这可以在多台设备上复制吗?重启后,你能告诉它正在监听哪个端口(netstat-an),然后在强制关闭应用程序后检查端口的可用性吗。。。没关系!这里的问题不是真的。我想问题不在你的设备上。我在Moto G和LG G2上有同样的问题。。。只有重新启动才能解决问题是的,它看起来真的像一个android bug。