I am developing a simple application that allows user to initiate call using sip protocol. The problem is inability to create SipSession in some cases (e.g. deleting application with active sip-session, and installing it again).
In this case, I am getting error:
android.net.sip.SipException: Failed to create SipSession; network unavailable?
And it works only after physical device reboot.
My Sip class:
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
I tried to remove this
sipSession = sipManager.createSipSession(sipProfile, new MySipSessionListener());
In this case I will not get any Exception, but SipRegistrationListener callbacks will not getting call.
And only reboot helps..
Someone faced this problem? I didn't find any correct solution for this..
SOLUTION The problem is in my device or firmware (Samsung Galaxy s4, Android 5.0.1 official, but some integrated apps were deleted with root). Checked on Samsung Galaxy s4 with Android 4.3.1 with cyanogen - no problem.