I have integrated pjsua2 in my android application. The application crashes when I send an SMS. It doesn't crash every time, it is happening randomly. (once every 10 messages).
MyCode is:
public void sendInstantMessage(String number, String msgBody) {
String buddy_uri = "<sip:" + number + "@" + mPref.getString(PREF_SIPSERVER, "") + ">";
Log.e(TAG, "sendInstantMessage ==== "+buddy_uri);
BuddyConfig bCfg = new BuddyConfig();
bCfg.setUri(buddy_uri);
bCfg.setSubscribe(false);
MyBuddy im = new MyBuddy(bCfg);
SendInstantMessageParam prm = new SendInstantMessageParam();
prm.setContent(msgBody);
prm.setContentType("text/plain; charset=utf-8");
try {
im.create(account, bCfg);
boolean valid1 = im.isValid();
Log.e(TAG, "valid1 ======= "+valid1);
im.sendInstantMessage(prm);
} catch (Exception e) {
Log.e(TAG, "sendInstantMessage ==== "+e);
e.printStackTrace();
return;
}
}
According to logcat , I have to call pj_thread_register(). But I have got a method libRegisterThread() in endpoint, so I used it like below
MyApp.ep.libRegisterThread("SipApi");
Here is the logcat:
../src/pj/os_core_unix.c:692: pj_thread_this: assertion "!"Calling pjlib from unknown/external thread. You must " "register external threads with pj_thread_register() " "before calling any pjlib functions."" failed
Here is the correct answer.