如何使用android.net.sip API从传出呼叫获取呼叫ID
问题描述:
我想知道如何在使用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);
}
});
但是当我拨打电话时没有任何方法正在被呼叫。
答
我终于找到了解决问题的方法,在这里它是:
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
对象进行呼叫的方法中使用该对象。
在sip会话中设置呼叫ID之前可能需要一点时间,给您一个空的呼叫ID,但是如果您在ss.getCallId()之前执行'Thread.sleep(100)'; '一定会给你通话ID。 – John 2012-08-02 12:54:08