我遵循Google的指导方针,在https://developer.android.com/guide/topics/connectivity/sip.html中创建应用SIP通话 我在sip.zadarma.com上创建了一个测试帐户,该帐户与我从Google Play下载的SIP客户端一起使用,但是当我尝试在我的应用程序中注册它时,我得到: onRegistrationFailed errorCode = -4 errorMessage:注册未运行 onRegistrationFailed errorCode = -9 errorMessage:0
@Override
protected void onResume() {
super.onResume();
if (mNumberKeyedIn == null)
mNumberKeyedIn = "";
if (hasSIPPermissions()) {
initializeSIP();
} else {
requestSIPPermission();
}
}
@Override
public void onPause() {
super.onPause();
closeLocalProfile();
}
public void closeLocalProfile() {
if (mSipManager == null) {
return;
}
try {
if (mSipProfile != null) {
mSipManager.close(mSipProfile.getUriString());
if (mSipManager.isRegistered(mSipProfile.getProfileName()))
mSipManager.unregister(mSipProfile, null);
}
} catch (Exception e) {
Log.d(TAG, "Failed to close local profile.", e);
}
}
private void initializeSIP() {
if (callReceiver == null) {
IntentFilter filter = new IntentFilter();
filter.addAction("com.xxxx.android.apps.xxxx.activity.INCOMING_CALL");
callReceiver = new IncomingCallReceiver();
this.registerReceiver(callReceiver, filter);
}
try {
if (mSipManager == null) {
mSipManager = SipManager.newInstance(this);
if (!SipManager.isVoipSupported(this)) {
Toast.makeText(this, getString(R.string.sip_not_supported), Toast.LENGTH_SHORT).show();
return;
}
if (SipManager.isSipWifiOnly(this)) {
Toast.makeText(this, getString(R.string.sip_wifi_only), Toast.LENGTH_SHORT).show();
}
}
if (mSipProfile != null) {
closeLocalProfile();
}
SipProfile.Builder builder = new SipProfile.Builder(BuildConfig.SIP_USERNAME, BuildConfig.SIP_DOMAIN);
builder.setPassword(BuildConfig.SIP_PASSWORD);
//builder.setProtocol("TCP");
//builder.setAuthUserName(BuildConfig.SIP_USERNAME);
//builder.setPort(5060);
//builder.setOutboundProxy(BuildConfig.SIP_OUTBOUND_PROXY);
builder.setAutoRegistration(true);
mSipProfile = builder.build();
Intent intent = new Intent();
intent.setAction("com.xxxx.android.apps.xxxx.activity.INCOMING_CALL");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
mSipManager.open(mSipProfile, pendingIntent, null);
mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
updateStatus(getString(R.string.sip_registering), R.drawable.circle_orange, false);
Log.d(TAG, "onRegistering " + localProfileUri);
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
updateStatus(getString(R.string.sip_ready), R.drawable.circle_green, true);
Log.d(TAG, "onRegistrationDone " + localProfileUri + " expiryTime = " + expiryTime);
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
updateStatus(getString(R.string.sip_registration_failed), R.drawable.circle_red, false);
Log.e(TAG, "onRegistrationFailed " + localProfileUri + " errorCode = " + errorCode + " errorMessage: " + errorMessage);
}
});
} catch (ParseException e) {
e.printStackTrace();
Toast.makeText(this, getString(R.string.sip_not_configured), Toast.LENGTH_SHORT).show();
} catch (SipException e) {
e.printStackTrace();
Toast.makeText(this, getString(R.string.oops_something_went_wrong_short), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, getString(R.string.sip_not_supported), Toast.LENGTH_SHORT).show();
}
}
非常感谢任何帮助。
答案 0 :(得分:0)
在测试您的注册服务器之前,应先尝试以下解决方案,然后再查看SipClient的代码。
虽然来自"错误记录"从您的文本意味着IP地址是可ping的但注册端口号没有打开。
我不认为这是代码问题。肯定是你的设置问题。