如何使用smack 4.1如何将信息查询包发送到xmpp服务器?

时间:2017-01-13 09:12:28

标签: android xmpp smack

如何向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>

1 个答案:

答案 0 :(得分:3)

iq标头和命名空间元素由smack本身处理或填充在xml中。下面给出了xml中的示例IQ数据包及其通过扩展IQ数据包的实现。

<iq to='jid@domain.in' 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;
}
}