我正在开发一个简单的应用程序,允许用户使用sip协议发起呼叫。问题是在某些情况下无法创建SipSession(例如,删除具有活动sip-session的应用程序,并重新安装它)。
在这种情况下,我得到错误:
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回调将不会得到调用。
只有重启才有帮助…
有人遇到这个问题吗?我没有找到任何正确的解决方法。
<<p> 解决方案/strong>问题出在我的设备或固件上(三星Galaxy s4、安卓5.0.1官方版本,但一些集成的应用程序被root用户删除了)。检查了三星Galaxy s4与Android 4.3.1的氰-没有问题。在尝试打开配置文件发送或接收呼叫之前创建您的SipSession。
sipSession = sipManager.createSipSession(sipProfile, new MySipSessionListener());
sipManager.open(sipProfile, pendingIntent, null);
我有同样的问题,并没有能够通过编程纠正它。当前的解决方案是添加一个延迟10秒的处理程序来检查OnRegistrationDone和OnRegistrationDone事件是否在这段时间内触发。下面的代码被直接放在管理器的前面。initializeLocalProfile函数中的setRegistrationListener方法。当检测到此错误条件时,将启动SIP首选项活动,并向用户发出SIP Library error通知,请求他们重新启动设备。同一处理程序还检测连接到已定义的SIP服务器的问题,并向用户发送server Not Found通知。这两种错误情况通常都会触发"注册超时"错误,但在该事件中无法区分这两种错误类型,并且需要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);