我需要在进行sip调用之前添加一个自定义标头。请帮帮我。
提前致谢。
答案 0 :(得分:1)
最后我得到了我的问题的答案。您应该更改 make makeSipCall()方法。
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;
}