I am using aSmack and Openfire for my chat application. I am able send and receive message finely. Openfire support offline message transfer when recipient is offline by keeping message until he comes online.
But what to do when sender is offline or his internet drops between communication?
Is there any api provided by aSmack/Smack which keeps message until internet is back ?
Or should i send my messages through SQLite ?
If you are connected to openfire and internet goes off then you are still online on openfire because you can't change presence if internet is off.
For this openfire use http://xmpp.org/extensions/xep-0199.html
If user app doesn't reply ping request then openfire makes it offline and offline storage starts.
For getting offline messages in asmack you need to add following providers.After adding these you will get offline messages if they are enabled from the server
pm.addIQProvider("offline", "http://jabber.org/protocol/offline",
new OfflineMessageRequest.Provider());
// Offline Message Indicator
pm.addExtensionProvider("offline",
"http://jabber.org/protocol/offline",
new OfflineMessageInfo.Provider());
ions/xep-0199.html
Well answering after a while, but perhaps still it would point someone in right direction.
After searching for a while, i get to know that aSmack doesn't provide any offline storage.
To send message when sender is offline, we need offline storage to store message until sender gets back online. I used sqlite
for this, but SharedPreferences would also be a good option if we have to delete message after successfull sending.
Best solution, which i follow is, insert message in sqlite
, store it's id in shared preferences
, send message and then remove id from shared preferences
. In mean while if intenet connection drops or message couldn't send by any reason, then we have it's id in shared preferences as backup. After getting online, we can go through shared preferences
to check if their is any message is pending to send.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With