Retrive offline messages

can any body give me idea about how to retrive offline msges,i use all 4 classes OfflineMessageHeader,OfflineMessageRequest,OffLineMessageInfo n OffLineMessageManager,

but i can,t understand how to retrive offline messages.

Hi inlove,

use this code

import java.util.Iterator;

import org.jivesoftware.smack.ConnectionConfiguration;

import org.jivesoftware.smack.XMPPConnection;

import org.jivesoftware.smack.packet.Message;

import org.jivesoftware.smackx.OfflineMessageManager;

public class OfflineTest {

public static void main(String[] args) throws Exception{

ConnectionConfiguration cc = new ConnectionConfiguration(“localhost”,5222);


XMPPConnection con = new XMPPConnection(cc);

// con.addPacketListener(new PacketListener(){


// public void processPacket(Packet pack) {

// System.out.println("Paket : "+pack.toXML() );

// }

// },null);


OfflineMessageManager omm = new OfflineMessageManager(con);


// OfflineMessageRequest omr = new OfflineMessageRequest();

// con.sendPacket(omr);

Iterator itr = omm.getMessages();



Message m =(Message);






i already use this code but i found a problem that messagecount value is always 0, i don’'t understand why it is happen,there is no problem in code as i think is there any other settings to retrive the offline msges,

Hi inlove,

Are you using this line for login ?


If no then you have to use this because here you are not sending your presence to the jabber server.

You will be logged in as an invisible to the Jabber server using below login() method.

You can do proper handling of the Offline messgaes(using above code) before sending presence to the Jabber server.


If you are using below to login, then all the offline messages are sent to the client when he sends the presence to the jabber. Below login() method sends the presence to the Jabber server after successfully login. So you can only get those offline messages in PacketListener().




Thank you, jchittoda !

It’'s OK!


i dont understand what type of login i have to use…

i try with myconnection.login(user,pass,res,false); but sometimes i receive offline messages, but the other times no.

could someone could post a complete example of a smack client that could receive offline message, or a full explain

of how do this?




Hey ,

Under the test folder check the org.jivesoftware.smackx.OfflineMessageManagerTest test case to find working example of offline messages. BTW, are you using Wildfire when you observe the random problem? If you do can you provide me the steps (or working code) to reproduce that problem?


– Gato