2012-08-01 169 views
0

我想知道如何在使用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。在進行音頻通話之前,我也正在做這件事:如何使用android.net.sip API從傳出呼叫獲取呼叫ID

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

     } 

    }); 

但是當我撥打電話時沒有任何方法正在被呼叫。

回答

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對象進行呼叫的方法中使用該對象。

+0

在sip會話中設置呼叫ID之前可能需要一點時間,給您一個空的呼叫ID,但是如果您在ss.getCallId()之前執行'Thread.sleep(100)'; '一定會給你通話ID。 – John 2012-08-02 12:54:08