我正在尝试使用pjsua2发送消息。但这是一个例外。请建议我。
这是我的代码
public void sendInstantMessage(String buddy_uri) {
buddy_uri = "sip:aaaaa@xxx.yyyyyy.zzz";
BuddyConfig cfg = new BuddyConfig();
cfg.setUri(buddy_uri);
cfg.setSubscribe(true);
MyBuddy im = new MyBuddy(cfg);
SendInstantMessageParam prm = new SendInstantMessageParam();
prm.setContent("Hi This is X, sending message");
boolean valid = im.isValid();
Log.e(TAG, "valid ======= "+valid);
try {
im.sendInstantMessage(prm);
} catch (Exception e) {
Log.e(TAG, "sendInstantMessage ==== "+e);
e.printStackTrace();
return;
}
}
抛出异常,这里是log
05-27 15:42:40.705: E/SipApi(27611): valid ======= false
05-27 15:42:40.706: A/libc(27611): ../src/pjsua-lib/pjsua_pres.c:231: pjsua_buddy_get_info: assertion "pjsua_buddy_is_valid(buddy_id)" failed
答案 0 :(得分:3)
最后,我得到了使用pjsip-2.4发送短信的解决方案
这是代码
/**Send message to this number
* @param String number
* @param String msgBody*/
public void sendInstantMessage(String number, String msgBody) {
String sipServer = "aaa.ggg.net";
String buddy_uri = "<sip:" + number + "@" + sipServer + ">";
BuddyConfig bCfg = new BuddyConfig();
bCfg.setUri(buddy_uri);
bCfg.setSubscribe(false);
MyBuddy myBuddy = new MyBuddy(bCfg);
SendInstantMessageParam prm = new SendInstantMessageParam();
prm.setContent(msgBody);
try {
myBuddy.create(account, bCfg);
myBuddy.sendInstantMessage(prm);
myBuddy.delete();
} catch (Exception e) {
e.printStackTrace();
return;
}
}