Cant get Offline message after re-connected to server with asmack-android-8-4.0.4

I am trying to make one simple Android chat application which can able to send message offline and online both way with use of asmack-android-8-4.0.4.

I am having issue with Offline messages . Behavior is very strange to me . i know there must be something which i am not getting correctly to manage offline messages .

Strange thing is , i am able to receive offline message in packet listener when i login after logout , but same thing not happen when i swtich off and on internet connectivity .After switch on internet the connection establish successfully but not receiving any callback from packet listen nor with use of OfflineMessageManager class .


I observed when i switch off internet , though that user is showing online over Openfire admin console who loged in . That means Openfire server dose not notified and consider that user Online and then its obvious it wont fetch offline messages. So now Question is how to change the status offline when internet connection goes away.? Do i have to write some code over Openfire server to manage this ?

Below is wrap of my code.

My Code

//Connect to xmpp server when internet comes

private void intConnection()


xMPPConfig = new ConnectionConfiguration(HOST,PORT);

if (connection == null)

connection = new XMPPTCPConnection(xMPPConfig);





KeyStore trustStore;


trustStore = KeyStore.getInstance(“AndroidCAStore”);

} else {

trustStore = KeyStore.getInstance(“BKS”);


TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());


try {

SSLContext sc = SSLContext.getInstance(“TLS”);

sc.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());


} catch ( e) {




connection.login(Uname, Pass, “Smack”);

OfflineMessageManager offlineMessageManager = new OfflineMessageManager(connection);;//This is the method get the offline message

Log.i(TAG, offlineMessageManager.getMessageCount()); //Here always getting 0

if (connectionListener!=null)


connection.addConnectionListener(connectionListener); //Here i add connectionListener

if (packetListener!=null)


connection.addPacketListener(packetListener, PacketFilter);

Presence presence = new Presence(Type.available);



try {


DeliveryReceiptManager.getInstanceFor(connection).addReceiptReceivedListener(ne w ReceiptManager());

} catch (Exception e) {



//Remove connect when internet off

public synchronized void doDisconnect(Context context) {

if (connection != null) {

if (packetListener != null)


if (connectionListener != null)


try {


} catch (NotConnectedException e) {



connection = null;

connectionListener = null;

packetListener = null;



That was totally funny , In my openfire server there was setting like :

i was getting offline message after login because i was changing the status of user as offline while they want to logout but in case when internet connection off i cant change status offline through asmack client to openfire server and that was the reason why it was not changing the user status till 360 sec and keep consider that user as online user.

Thanks for the post, How to change the Disconnect timeout to 5 seconds in Ejabberd server please let me know and i will be grateful to you for your next reply