Android Background Service for Smack Chat Application (XMPP)

I am using a chat application using the asmack library. I want to start an always-running service, where the entire connection management task should be performed, and which should continue to receive incoming packets and store messages in my sqlite database. And when my application is launched, I want my application to be notified of incoming messages as well, while the background service inserts messages into the sqlite database. How to implement such a structure with a sticky service. A partial tracking lock is also required. Since images also need to be downloaded using http, sometimes sometimes on a specific request.

+6
source share
1 answer

You can start the service after registering with the server.

onStartCommand user login service.

Deploy a service using PacketListener, ConnectionListener, InvitationListener

PacketListener to receive Groupcaht or One one One chat messages.

ConnectionListener to check if the connection to the server is connected or disconnected.

InvitingListener . To receive group invitations.

After successfully logging in, add these listeners.

Now that the message is received, save this message in the local database and send a broadcast for actions that want the message to be received.

Check if the app is running in the background, if so, then send a notification for a new message

Email me if any buddy ran into any problem cvofjaspreet@gmail.com

+14
source

All Articles