如何向xmpp服务器发送信息查询包,即如何向服务器发送“…”来查询某些信息?

<iq type='set' id='123'>
 <push xmlns='p1:push'>
   <keepalive max="30"/>
   <session duration="60"/>
   <body send="all" groupchat="true" from="jid"/>
   <status type="xa">Text Message when in push mode</status>
   <offline>false</offline>
   <notification>
       <type>applepush</type>
       <id>DeviceToken</id>
   </notification>
   <appid>application1</appid>
 </push>
</iq>

最佳答案

iq头和名称空间、元素由smack本身在xml中处理或填充。下面给出一个XML格式的示例IQ包及其扩展IQ包的实现。

<iq to='[email protected]' id='khz0k-13678' type='get'><elementName xmlns='http://jabber.org/protocol/muc#something'><item affiliation="member"/></elementName></iq>

public class IQGetSomething extends IQ {
public static final String ELEMENT = "elementName";
public static final String NAMESPACE = "http://jabber.org/protocol/muc#something";
String memberType;

public IQGetSomething() {
    super(ELEMENT, NAMESPACE);
    setType(Type.get);
}

public String getMemberType() {
    return memberType;
}

public void setMemberType(String memberType) {
    this.memberType = memberType;
}


@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
    xml.rightAngleBracket();
    xml.append("<item affiliation=\"").escape(memberType).append("\"/>");
    return xml;
}
}

关于android - 如何使用smack 4.1向xmpp服务器发送信息查询包?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41630978/

10-09 07:23