Quantcast
Channel: Ignite Realtime : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 10742

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

$
0
0

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 .

 

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);

SASLAuthentication.supportSASLMechanism("PLAIN",0);

xMPPConfig.setSecurityMode(SecurityMode.disabled);

 

xMPPConfig.setReconnectionAllowed(false);

xMPPConfig.setSendPresence(false);

 

KeyStore trustStore;

         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

             trustStore = KeyStore.getInstance("AndroidCAStore");

         } else {

             trustStore = KeyStore.getInstance("BKS");

         }

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

         trustManagerFactory.init(trustStore);

try {

SSLContext sc = SSLContext.getInstance("TLS");

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

this.xMPPConfig.setCustomSSLContext(sc);

} catch (java.security.GeneralSecurityException e) {

e.printStackTrace();

}

connection.connect();

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.removeConnectionListener(connectionListener);

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

 

if (packetListener!=null)

  connection.removePacketListener(packetListener);

   connection.addPacketListener(packetListener, PacketFilter);

 

Presence presence = new Presence(Type.available);

  presence.setMode(Presence.Mode.available);

   connection.sendPacket(presence);

 

try {

  DeliveryReceiptManager.getInstanceFor(connection).enableAutoReceipts();

  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)

     connection.removePacketListener(packetListener);

if (connectionListener != null)

     connection.removeConnectionListener(connectionListener);

try {

     connection.disconnect();

} catch (NotConnectedException e) {

     e.printStackTrace();

}

     connection = null;

     connectionListener = null;

     packetListener = null;

     }

}


Viewing all articles
Browse latest Browse all 10742

Trending Articles