https://github.com/android/platform_development/tree/master/samples/SipDemo
上面是Android自带的SipDemo,下
https://developer.android.com/reference/android/net/sip/package-summary.html
Android 官网对sip的相关使用的介绍。
使用
1、注册广播
private void registerInComingCallReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction("android.SipDemo.INCOMING_CALL");
callReceiver = new IncomingCallReceiver();
this.registerReceiver(callReceiver, filter);
}
2、实例SipManager
if (manager == null) {
manager = SipManager.newInstance(this);
}
3、SipProfile
SipProfile.Builder builder = new SipProfile.Builder("Android004", "115.236.167.22");
builder.setPassword("78cdb4164g");
// builder.setOutboundProxy("45.56.91.117");
me = builder.build();
4、设置接听电话广播,如果不需要接电话可以直接manager.open(me);就可以了
Intent i = new Intent();
i.setAction("android.SipDemo.INCOMING_CALL");
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA);
manager.open(me, pi, null);
5、设置是否登录成功的监听,必须在上面的open方法之后调用
manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
//修改textview显示的文字
updateStatus("Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
updateStatus("Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
updateStatus("Registration failed. Please check settings.");
}
});
6、初始化电话
//sipaddress电话号码
updateStatus(sipAddress);
SipAudioCall.Listener listener = new SipAudioCall.Listener() {
// Much of the client's interaction with the SIP Stack will
// happen via listeners. Even making an outgoing call, don't
// forget to set up a listener to set things up once the call is established.
@Override
public void onCallEstablished(SipAudioCall call) {