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

时间:2012-08-01 07:53:01

标签: android sip

我想知道在使用android.net.sip API拨打电话时如何获取电话ID。 我目前只是在android sip演示中拨打电话。 call = manager.makeAudioCall(me.getUriString(), sipAddress, listener, 30);
我还在文档中看到,您可以在拨打电话时创建一个SIP会话以获取呼叫ID,但我无法弄明白。有关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);

        }

    });

但在拨打电话时没有调用任何方法。

1 个答案:

答案 0 :(得分:0)

我终于找到了问题的解决方案,现在是:

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;
}

我们只是创建自己的SipAudioCall对象,而不是使用我们的经理进行调用。我们使用我们的经理创建SipSession,我们将在方法中使用SipAudioCall对象进行调用。