How to get the call Id from an outgoing call using

2019-04-17 16:20发布

问题:

I am wondering how you can get the call id when you make an outgoing call using the android.net.sip API. I am currently just making an outgoing call as they do in the android sip demo. 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. 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:

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.

回答1:

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. We use our manager to create a SipSession, which we will use in the method for making a call with our SipAudioCall object.



标签: android sip