我想使用Smack Android Library将以下IQ节发送到Ejabberd XMPP Server。我怎么发送?
<iq from='hag66@shakespeare.example'
to='coven@muc.shakespeare.example'
type='set'
id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'>
<subscribe xmlns='urn:xmpp:mucsub:0'
nick='mynick'
password='roompassword'>
<event node='urn:xmpp:mucsub:nodes:messages' />
<event node='urn:xmpp:mucsub:nodes:affiliations' />
<event node='urn:xmpp:mucsub:nodes:subject' />
<event node='urn:xmpp:mucsub:nodes:config' />
</subscribe>
</iq>
我希望订阅MUC / Sub活动,如https://docs.ejabberd.im/developer/xmpp-clients-bots/proposed-extensions/muc-sub/
中所述答案 0 :(得分:0)
我已经使用以下代码,请检查可能对您有帮助。
try {
IQ iq=new IQ("mynick","urn:xmpp:mucsub:0") {
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.setEmptyElement();
return xml;
}
};
iq.setType(IQ.Type.get);
//add your urn:xmpp:muclight:0#affiliations extension element
iq.addExtension();
iq.setTo(AppConstants.CHAT_HOSTNAME);
iq.setFrom(connection.getUser());
debugLog("ping send stanza:"+iq.toXML());
connection.sendStanza(iq);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}