我尝试在 android 上编写一个简单的 SIP 应用程序。我正在使用 android API 19 并使用星号作为 SIP 服务器。但是我发现每次执行 SipManager.open() 时,它都会注册两次。当我打电话时,两个 channel 都在呼唤。
我的代码如下:
Intent intent = new Intent();
intent.setAction(ACTION_INCOMING_CALL);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
if (mSipManager == null) {
mSipManager = SipManager.newInstance(this);
}
SipProfile.Builder builder = new SipProfile.Builder("<some sip id>", SIP_SERVER);
builder.setPassword("<sip password>");
mSipProfile = builder.build();
mSipManager.close(mSipProfile.getUriString());
mSipManager.open(mSipProfile, pendingIntent, null);
mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
updateStatus("Registering");
Log.d("SipActivity", "Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
updateStatus("Ready");
Log.d("SipActivity", "Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
updateStatus("Registration failed." + errorCode + " >>>" + errorMessage);
Log.d("SipActivity", "Registration failed. Please check settings." + errorMessage);
}
});
我已放置日志以确保我调用了一次打开,但日志显示两次“正在向 SIP 服务器注册”和两次“就绪”。
最佳答案
我找到了它注册两次的原因。 在 onRegistrationDone 上记录 expiryTime 后,第一个事件是 -1,这意味着 session 已过期。因此,由于 autoRegister 标志为真,它将再次注册。
关于android - SIP在android上注册两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26524288/