//To retrieve archive msges from server.. MyCustomIQ iq = new MyCustomIQ(); iq.setType(IQ.Type.set); mConnection.sendIqWithResponseCallback(iq, new PacketListener() { @Override public void processPacket(Packet packet) throws SmackException.NotConnectedException { Log.i("Send IQ with Response", "****** message " + packet); } }, new ExceptionCallback() { @Override public void processException(Exception exception) { exception.printStackTrace(); Log.i("IO archjieve Exception",""+ exception.getMessage()); } }, 5000); mConnection.sendPacket(new Presence(Presence.Type.available)); PacketTypeFilter filter=new PacketTypeFilter(org.jivesoftware.smack.packet.Message.class); PacketListener myListener=new PacketListener(){ public void processPacket(Packet packet){ if(((Message) packet).getType().equals(Message.Type.chat)) { ((Message) packet).getBody(); } else if(((Message) packet).getType().equals(Message.Type.normal)) { DefaultPacketExtension pacExten=PacketUtil.packetExtensionfromCollection(packet.getExtensions(), "result", "urn:xmpp:mam:0"); String strMsg=pacExten.getValue("body"); } } } ; mConnection.addPacketListener(myListener, filter); //My Custom IQ class MyCustomIQ extends IQ { String token; protected MyCustomIQ() { super("query","urn:xmpp:mam:0"); } @Override protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { // String queryId = prefix + Long.toString(new AtomicLong().incrementAndGet()); xml.attribute("queryid",queryId); xml.rightAngleBracket(); return xml; } } //You may get the response in PacketListerener sometimes so put debug in that also
source share