How to add custom header while making a pjsip makecall()?

我怕爱的太早我们不能终老 提交于 2019-12-13 03:39:39

问题


I need to add one custom header for before making a sip call. please help me.

Thanks in advance.


回答1:


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


来源:https://stackoverflow.com/questions/25861154/how-to-add-custom-header-while-making-a-pjsip-makecall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!