Search code examples
androidxmppofflineasmacksender

How to send XMPP message when sender is offline?


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 ?


Solution

  • 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.