android sip协议通话实现

2018-01-23  本文已影响0人  endian

android sip协议通话代码实现



<tr>
<th> SipSession.State</th>
<th>定义SIP会话的声明,比如“注册”、“呼出电话”、“打入电话”</th>
</tr>
<tr>
<th> SipRegistrationListener</th>
<th> 一个关于SIP注册事件监 听器的接口</th></tr></tbody></table>




    SipProfile.Builder builder = new SipProfile.Builder(username, domain); 
    //uesrname表示注册用户名,domain表示域,实际就是sip服务器ip
    builder.setPassword(password); //注册用户密码
    SipProfile me = builder.build(); //构造一个SipProfile对象,也就是相当于一个账户信息
    Intent i = new Intent();
    i.setAction("android.SipDemo.INCOMING_CALL");
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA); 
    //构造一个PendingIntent对象,这样当sip Service收到一个通话请求时,
    //例如收到一个来电时,SipService会调用PendingIntent的send方法发送相应广播消息给调用者,也就是当前的SipProfile对象.
    manager.open(me, pi, null); //此处就是用于注册一个账户到sip服务器

//注册一个监听器,用于获取注册账户时的通知状态,当然也可以不注册.

        manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
        public void onRegistering(String localProfileUri) { //正在注册
        }

        public void onRegistrationDone(String localProfileUri, long expiryTime) {//注册成功
        }

        public void onRegistrationFailed(String localProfileUri, int errorCode,
                String errorMessage) {
        }
    });

从localProfile和peerProfile指定的内容可以看出,账户名作为唯一标识,由sip服务器来解析账户名,从而找到对应的目的主机.

上一篇 下一篇

猜你喜欢

热点阅读