所以,我已经使用Androids Sip库编写了这个Android Sip应用程序一段时间,但我无法让注册工作.目前,当我打电话时,它给我以下错误SipManager.register():android.net.sip.SipException: SipService.createSession() returns null.
我的代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
运行它会提供以下输出:
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
Run Code Online (Sandbox Code Playgroud)
有谁知道我在这里做错了什么?此外,我正在尝试手动注册sip配置文件,而不是使用自动注册.(顺便说一下我关于stackoverflow的第一个问题,所以请温柔:))
似乎至少有另一个怪癖导致相同的错误代码.如果您的手机上碰巧有一个预定义的帐户具有相同的请求URI,那么您尝试在应用中创建的第二个帐户就会失败.请注意,即使未为传入呼叫设置该帐户(=后端的SIP注册),也会发生这种情况.我希望Android团队能解决这个问题,或者至少会抛出一个有意义的错误.
更新:通过该解决方案,异常消失了,但我无法接到任何电话。
我刚刚找到了解决方案。在致电注册之前,您必须先致电开放。另外,不要使用开放的侦听器(SipDemo 是这么说的,不确定为什么),而是在注册后注册它(对我有用)。
所以我的代码是:
manager.open(localProfile, pendingIntent, null);
manager.register(localProfile, 20, listener);
manager.setRegistrationListener(localProfile.getUriString(), listener);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3472 次 |
| 最近记录: |