Android 未注册本地SipProfile的SipAudioCall
我正在尝试使用本机Android SIP堆栈在局域网内进行直接SIP调用。在本机堆栈中,似乎需要注册本地配置文件才能进行SIP调用 下面是我(尝试)用于注册配置文件的代码。我在这个网络上没有SIP服务器,所以我只使用localhost作为域Android 未注册本地SipProfile的SipAudioCall,android,sip,Android,Sip,我正在尝试使用本机Android SIP堆栈在局域网内进行直接SIP调用。在本机堆栈中,似乎需要注册本地配置文件才能进行SIP调用 下面是我(尝试)用于注册配置文件的代码。我在这个网络上没有SIP服务器,所以我只使用localhost作为域 if (mSipManager == null) { mSipManager = SipManager.newInstance(mContext); try { SipProfile.Buil
if (mSipManager == null) {
mSipManager = SipManager.newInstance(mContext);
try {
SipProfile.Builder builder = new SipProfile.Builder("foo", "localhost");
builder.setPassword("bar");
mSipProfile = builder.build();
mSipManager.register(mSipProfile, 30000, new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
Log.v(TAG, "Registering with profile with SIP Server. URI: " + localProfileUri);
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
Log.v(TAG, "Registered with profile with SIP Server. URI: " + localProfileUri);
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
Log.e(TAG, "Registration failed. Code: " + Integer.toString(errorCode));
Log.e(TAG, errorMessage);
}
});
} catch (ParseException e) {
Log.e(TAG, "Unable to set up local SipProfile.", e);
} catch (SipException e) {
Log.e(TAG, "Unable to open local SipProfile.", e);
}
}
在其他地方,这里是我打电话的代码:
try {
Log.v(TAG, "VOIP Supported: " + SipManager.isVoipSupported(mActivity));
Log.v(TAG, "SIP API Supported: " + SipManager.isApiSupported(mActivity));
SipProfile.Builder builder = new SipProfile.Builder(mSipUri);
SipProfile remote = builder.build();
SipAudioCall.Listener listener = new SipAudioCall.Listener() {
@Override
public void onCalling(SipAudioCall call) {
Log.d(TAG, "SIP Call initiating...");
}
@Override
public void onCallEstablished(SipAudioCall call) {
Log.d(TAG, "SIP Call established.");
call.startAudio();
call.setSpeakerMode(true);
call.toggleMute();
}
@Override
public void onCallEnded(SipAudioCall call) {
Log.d(TAG, "SIP Call ended.");
}
@Override
public void onError(SipAudioCall call, int errorCode, String errorMessage) {
Log.e(TAG, "SIP Call Error. Code: " + Integer.toString(errorCode));
Log.e(TAG, errorMessage);
}
};
mSipCall = mSipManager.makeAudioCall(mSipProfile, remote, listener, 10);
} catch (ParseException e) {
Log.e(TAG, "Unable to set up remote SipProfile.", e);
} catch (SipException e) {
Log.e(TAG, "SipAudioCall error.", e);
}
这将导致以下logcat输出:
11-20 11:46:33.150 1412-1412/package.name E/XmlTest﹕ 1- Unable to open local SipProfile.
android.net.sip.SipException: SipService.createSession() returns null
at android.net.sip.SipManager.register(SipManager.java:481)
我无法找到createSession返回null的更多细节;是因为我没有为配置文件提供有效的服务器进行注册吗?如果是这样,有没有一种不用向服务器注册就可以使用本机SIP堆栈的方法?问题是Android的SIP堆栈似乎需要您提供给SIPManager的本地SIP配置文件(在上面的第一个代码块中,由
builder
和mSipProfile
表示)为其提供有效的IP地址
在我最初指定“localhost”的地方,您必须实际提供进行SIP调用的任何接口的IP地址;如果您使用的是VPN,则必须提供VPN接口的IP。我遇到这样的问题。你能说一下你到底写了什么作为这个参数吗?你忘了mSipManager.open(…)了吗?这确实导致SipService.createSession()为我返回null。