Google XMPP聊天服务发现返回空响应

时间:2012-03-17 02:47:06

标签: xmpp smack asmack

我一直在为Android编写聊天应用程序。

我正在实施Google Talk共享状态消息功能。 http://code.google.com/apis/talk/jep_extensions/shared_status.html

我必须发送此节

<iq type='get' to='gmail.com'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>

我的代码(使用SMACK api)是:

    final IQ iq = new IQ() {
        public String getChildElementXML() { 
            return "<query xmlns='http://jabber.org/protocol/disco#info'/>"; 
        }
    };

    iq.setTo("gmail.com");
    iq.setType(IQ.Type.GET);

    Log.w("IQ", "Prepared packet " + iq.toXML());
    Log.w("IQ", "Sending 1");
    connection.sendPacket(iq);

我希望收到以下数据包:

<iq xmlns='jabber:client' from='gmail.com' type='result'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <identity category='server' type='im' name='Google Talk'/>
    <feature var='http://jabber.org/protocol/disco#info'/>
    <feature var='google:jingleinfo'/>
    <feature var='google:roster'/>
    <feature var='google:nosave'/>
    <feature var='google:setting'/>
    <feature var='google:shared-status'/>
    <feature var='http://jabber.org/protocol/archive#otr'/>
    <feature var='google:mail:notify'/>
    <feature var='http://jabber.org/protocol/archive#save'/>
    <feature var='http://jabber.org/protocol/rosterx'/>
  </query>
</iq>

我的听众收到了数据包:

public void processPacket(Packet    
    //IQ iq = (IQ) packet;
    Log.w("IQ", "Packet received " + packet.toXML());
}

收到后,我收到以下日志:

03-17 08:05:43.129: W/IQ(1050): Packet received <iq id="fYhYL-4" to="abdurrahim.ceg@gmail.com/androidC2AEBEEF" from="gmail.com" type="result"></iq>

我做错了什么?

提前致谢!

1 个答案:

答案 0 :(得分:0)

发送数据包没有问题。我必须写一个IQProvider或PacketExtensionProvider来解析传入的数据包,因为smack不理解这些自定义数据包。