I'm using asmack the latest version (asmack-android-8-source-0.8.3) in a android project and I have the following code:
connection.addPacketListener(new PacketListener()
{
@Override
public void processPacket(Packet p)
{
if(p.getPacketID().equals("v3"))
{
Log.e("TAG", p.toXML());
}
}
}, new IQTypeFilter(IQ.Type.RESULT));
Packet iq = new Packet()
{
@Override
public String toXML()
{
String str = "<iq type='get' id='v3'><getservertime xmlns='urn:xmpp:mrpresence'/></iq>";
Log.e("TAG", str);
return str;
}
};
//sends <iq type='get' id='v3'><getservertime xmlns='urn:xmpp:mrpresence'/></iq>
connection.sendPacket(iq);
in the debugger the response it's ok and this is expected:
<iq type="result" id="v3" to="minimaal@mrserver/Smack">
<servertime xmlns="urn:xmpp:mrpresence" utc="2013-06-28T11:45:32.380Z" local="2013-06-28T07:45:32.380Z"/>
</iq>
but p.toXML() in the package listner, the tag "servertime" it's missing:
<iq id="v3" to="minimaal@mrserver/Smack" type="result"></iq>
Any suggestions on what I'm doing wrong?
<servertime/>
is a custom child element, which is not known to Smack. It is simply ignored when parsing the stanza. You need to make Smack aware of the element, by creating a new PacketExtension which needs to get registered with the ProviderManager
.
You can read more about it in Smack's documentation about the Provider Architecture.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With