So, I've been coding this Android Sip application using Androids Sip library for some time, but i can't get the registration to work. Currently it gives me the following error when i call SipManager.register()
: android.net.sip.SipException: SipService.createSession() returns null
.
My code:
public static void Register(final String username, final String password, final String domain, final String cbf)
throws ParseException, SipException {
Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register");
/*
* Luodaan SIP-profiili
*/
SipProfile.Builder builder = new SipProfile.Builder(username, domain);
builder.setPassword(password);
//builder.setProtocol("TCP");
//builder.setPort(5060);
builder.setAutoRegistration(false);
_sipprofile = builder.build();
Intent intent = new Intent();
intent.setAction("android.jahtipuhelin.INCOMING_CALL");
PendingIntent pendingIntent = PendingIntent.getBroadcast(_context, 0, intent, Intent.FILL_IN_DATA);
_sipmanager.open(_sipprofile, pendingIntent, new SipRegistrationListener() {
@Override
public void onRegistering(String s) {
Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 0");
}
@Override
public void onRegistrationDone(String s, long l) {
Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 1");
try {
_sipmanager.register(_sipprofile, 30, null);
_sipmanager.setRegistrationListener(_sipprofile.getUriString(), new JPSipRegistrationListener(_class, cbf));
} catch (SipException e) {
Log.e(MainActivity.LOGTAG,e.getClass().toString()+ ": "+ e.getMessage());
e.printStackTrace();
}
}
@Override
public void onRegistrationFailed(String s, int i, String s2) {
Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 2");
Log.d(MainActivity.LOGTAG, s2);
try {
_sipmanager.register(_sipprofile, 30, null);
_sipmanager.setRegistrationListener(_sipprofile.getUriString(), new JPSipRegistrationListener(_class, cbf));
} catch (SipException e) {
Log.e(MainActivity.LOGTAG,e.getClass().toString()+ ": "+ e.getMessage());
e.printStackTrace();
}
}
});//*/
Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - 2");
}
private static class JPSipRegistrationListener implements SipRegistrationListener {
private MainActivity _parent;
private String _callBack;
public JPSipRegistrationListener(MainActivity ma, String callBack) {
this._parent = ma;
this._callBack = callBack;
}
@Override
public void onRegistering(String localProfileUri) {
Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistering");
_parent.callSub(_callBack, REGISTERING, 0, "");
}
@Override
public void onRegistrationDone(String localProfileUri, long expiryTime) {
Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistrationDone");
_parent.callSub(_callBack, REGISTRATION_DONE, 0, "");
}
@Override
public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistrationFailed");
Log.e(MainActivity.LOGTAG, "Virhe Sip-rekisteröinnissä: "+errorCode+": "+errorMessage);
if (errorCode == -10) {
return;
}
_parent.callSub(_callBack, REGISTRATION_FAILED, errorCode, errorMessage);
}
}
Running that gives the following output:
08-11 18:50:58.276 24449-24449/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register
08-11 18:50:58.436 24449-24465/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register - testi 2
08-11 18:50:58.436 24449-24465/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: registration not running
08-11 18:50:58.446 24449-24449/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register - 2
08-11 18:50:58.666 24449-24465/fi.hieta.aatu.android.jahtipuhelin E/fi.hieta.aatu.android.jahtipuhelin: class android.net.sip.SipException: SipService.createSession() returns null
Does anyone know what i am doing wrong here? Also, I'm trying to manually register the sip profile, not by using autoregistration. (btw my first question on stackoverflow, so please be gentle :))