Can't get messages history in android - XMPP



I've been looking for solution for this problem for more than 3 days now.. :/


I'm making a chat app for android using xmpp - openfire server. I successfully connected and logged into server and now I'm able to chat with Spark from my app..


But now I have to get the recent messages in the one-one chat (history) I read that I have to use a plugin and request the messages.. I used Monitoring Service Plugin and Open Archive Plugin using the following request :



<iq type='get' id='user1'>
<list xmlns='urn:xmpp:archive'
with='admin@localhost'>
<set xmlns='http://ift.tt/1jsKSY9'><max>30</max>
</set></list></iq>


which I sent from android like that :



Packet packet = new Packet() {
@Override
public String toXML() {
String xExtension = "<iq type='get' id='user1'>"+
"<list xmlns='urn:xmpp:archive'"+
" with='admin@localhost'>"+
"<set xmlns='http://ift.tt/1jsKSY9'><max>30</max></set></list></iq>";
return xExtension;
}
};
MainActivity.connection.sendPacket(packet);


And the PackageListener :



PacketFilter filter = new PacketFilter() {
public boolean accept(Packet arg0) {
return true;
}
};
MainActivity.connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
if(packet.getClass() == Message.class ) {
Message message = (Message) packet;
final String body = message.getBody();
final String from = message.getFrom();
Log.d(TAG, "Got Message : " + body);
} else {
Log.d("Chat", "Packet: " + packet.getClass());
System.out.println("packet details : " + packet.toXML());
}
}
}, filter);


So I get the response as follow :



packet details : <iq id="user1" to="user2@localhost/Smack" type="result"></iq>


Why I don't get the chats although I can see them in Openfire Admin Console..? Any Help Will Be Very Appreciated.. Thanks.


No comments:

Post a Comment