简体   繁体   English

如何使用android.net.sip API从拨出电话中获取呼叫ID

[英]How to get the call Id from an outgoing call using android.net.sip API

I am wondering how you can get the call id when you make an outgoing call using the android.net.sip API. 我想知道当您使用android.net.sip API拨打电话时如何获得通话ID。 I am currently just making an outgoing call as they do in the android sip demo. 我目前正在拨打电话,就像他们在android sip演示中一样。 call = manager.makeAudioCall(me.getUriString(), sipAddress, listener, 30);
I also saw in the documentation that you can create a sip session when making a call in order to get the call id, but I just can't figure it out. 我还在文档中看到,您可以在拨打电话时创建一个sip会话以获取通话ID,但我无法弄清楚。 See http://developer.android.com/reference/android/net/sip/SipManager.html#createSipSession(android.net.sip.SipProfile for the documentation on the SipManager . I am also doing this before I make the audio call: 有关SipManager上的文档,请参见http://developer.android.com/reference/android/net/sip/SipManager.html#createSipSession(android.net.sip.SipProfile 。在进行音频通话之前,我也在这样做:

manager.createSipSession(me, new SipSession.Listener(){
        @Override
        public void onCalling(SipSession session) {
            String callId = session.getCallId();
            Log.d(TAG, "onCalling. call ID: " + callId);
        }
        @Override
        public void onRingingBack(SipSession session) {
            String callId = session.getCallId();
            Log.d(TAG, "onRinging. call ID!!!: " + callId);
        }
        @Override
        public void onCallEstablished(SipSession session,
                String sessionDescription) {
            String callId = session.getCallId();
            Log.d(TAG, "onCallEstablished: call ID!!!: " + callId);

        }

    });

but none of the methods are being called when I make the outgoing call. 但是我打出电话时没有方法被调用。

I finally found a solution to the problem, and here it is: 我终于找到了解决问题的方法,这里是:

private SipAudioCall myMakeAudioCall(Context context, SipProfile sipProfile, SipProfile peerProfile, int timeout) throws SipException{

    SipAudioCall.Listener l = new SipAudioCall.Listener(){
        @Override
        public void onCallEstablished(SipAudioCall call) {
        }
        //add more methods if you want to
    };

    SipAudioCall testCall = new SipAudioCall(context,sipProfile);
    testCall.setListener(l);

    SipSession.Listener sessionListener = new SipSession.Listener(){
        @Override
        public void onCalling(SipSession session) {
            String callId = session.getCallId();
            Log.d(TAG, "onCalling. call ID: " + callId);
        }
        //add more methods if you want to
    };

    SipSession ss = manager.createSipSession(sipProfile, sessionListener);
    if(ss == null){
        throw new SipException("Failed to create SipSession; Network available?");
    }
    testCall.makeCall(peerProfile, ss, timeout);
    Log.d(TAG,"iD: " + ss.getCallId());
    return testCall;
}

Instead of making a call using our manager, we simply create our own SipAudioCall object. 无需使用管理器进行呼叫,我们只需创建自己的SipAudioCall对象即可。 We use our manager to create a SipSession , which we will use in the method for making a call with our SipAudioCall object. 我们使用我们的管理器创建一个SipSession ,我们将在用于与SipAudioCall对象进行通话的方法中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM