I need to add one custom header for before making a sip call. please help me.
Thanks in advance.
I need to add one custom header for before making a sip call. please help me.
Thanks in advance.
Finally i got the answer for my question. You should change your make makeSipCall() method.
private boolean makeSipCall(String phoneNumber)
{
if(!created)
return false;
Log.i("MtaAPIImpl", (new StringBuilder("makecall : ")).append(phoneNumber).toString());
phoneNumber = (new StringBuilder("<sip:")).append(phoneNumber).append("@").append(sipServer).append(">").toString();
byte userData[] = new byte[1];
int callId[] = new int[1];
pjsua_call_setting cs = new pjsua_call_setting();
pjsua.call_setting_default(cs);
cs.setVid_cnt(0L);
cs.setAud_cnt(1L);
cs.setFlag(0L);
pjsua_msg_data msgData = new pjsua_msg_data();
pjsua.msg_data_init(msgData);
pj_pool_t pool = pjsua.pool_create("call_tmp", 512L, 512L);
pjsua.csipsimple_init_acc_msg_data(pool, 1, msgData);
pj_str_t uri = pjsua.pj_str_copy(phoneNumber);
//Here adding headers adding through bundel.
Bundle extra_header = new Bundle();
final Bundle b = new Bundle();
extra_header.putString("header-Name", "Header-Value");
b.putBundle(SipCallSession.OPT_CALL_EXTRA_HEADERS, extra_header);
Bundle extraHeaders = b.getBundle(SipCallSession.OPT_CALL_EXTRA_HEADERS);
for (String key : extraHeaders.keySet()) {
try {
String value = extraHeaders.getString(key.toString());
if (!TextUtils.isEmpty(value)) {
int res = pjsua.csipsimple_msg_data_add_string_hdr(pool, msgData,pjsua.pj_str_copy(key), pjsua.pj_str_copy(value));
if (res == pjsuaConstants.PJ_SUCCESS) {
Log.e(THIS_FILE, "Failed to add Xtra hdr (" + key + " : "+ value + ") probably not X- header");
}
}
} catch (Exception e) {
Log.e(THIS_FILE, "Invalid header value for key : " + key);
}
}
int status = pjsua.call_make_call(1, uri, cs, userData, msgData, callId);
pjsua.pj_pool_release(pool);
return status == pjsuaConstants.PJ_SUCCESS;
}