Android background service for Smack (XMPP) chat application - android

I am implementing a chat app using asmack library. I want to start a always running service where all the connection management task is to be done and that should be keep on receiving the incoming packets and saving the messages in my sqlite database. And as my app is launched I want my app to be notified too for the incoming messages while the background service is inserting the messages into sqlite database.
How to implements such structure with sticky service. Is partial wake lock also needed. Since, images are also to be downloaded using http partially sometimes on specific demand.

You can start the service after registration on the server.
onStartCommand of service login the user.
Implement service with PacketListener,ConnectionListener,InvitationListener
PacketListener for Receiving Groupcaht or One to One chat messages.
ConnectionListener to check if connection to the server is connected or disconnected.
InvitationListener For getting Group invitations.
After successful login add these listeners.
Now when the message is received save that message in local database and send a Broadcast for the activities who want the message to be received.
Check if the app is in the background if yes then send the notification for the new message
Mail me if any buddy face any issue cvofjaspreet#gmail.com

Related

Start a service in background which does gets destroyed as in Whatsapp

I am building a chat app using firebase . I want to show notification for new messages when the app is in background/foreground/terminated . I tried to show it using background service but it gets killed everytime app is destroyed. I know it can be done using FCM but i don't want to use it . It can also be done using foreground service but i don't want that strict notification .
I explored various blogs and i came to know this happens because it runs in same process and to create another process it get complex from Oreo and higher versions.
I also come to know JobService but it minimum periodic time is 15 minutes and if implemented will lose the real time notification nature.
How it can be implemented as in WhatsApp ?
If you see the setting of WhatsApp you will see that 1 Process and 1 Service message keeps showing indicating that MessageService is still running which means that it can be done using background service
I come to know that WhatsApp is also using FCM kind of thing with high priority to show notification.
It simply syncs the changes in database when data message is recieved using FCM.
This data message can be send using either firebase GUI or trusted environment like admin-sdk ..
I used the later one to send data message using admin-sdk from my server.
I have used APIs with device token of user as data message to send a POST request to my server which sends notification as data message to receiver device to trigger syncing .
Once Syncing is finished , i have send notification accordingly.

How to check the Notification Received Status from Firebase in my Server

I have setup push notification service with Firebase, I'm sending notifications with the help of REST API, notification are received by different clients at different times based on their token.
There can be different reasons when a user will not be able to receive the notifications for e.g. he don't have Internet connection.
So I need the status from client side that either the notification is received on the device or not or it is in pending state? with the notification details
I need to get this info and save it in my server. How this can be achieved?

How to continuously make a http request and respond with push notification if data is available

I'm developing an app in which I wanted to implement some notifications features for the user. Every user notification is saved in a back end sql database. What I've done so far is to create a Android service in which after a certain delay, an HTTP request is made to check if database has new notifications for the user by processing its json reply and notify the user if something is available.
After some research I've done, I have come to conclusion that this in not battery-friendly and I "have" to use Push Notifications using some service like gcm or fcm.
So my problem is now this:
How to properly make a request to the database every for example 1
sec. and check if any notification is available and THEN make a
push notification so that the device is triggered to fetch the
notifications themselves from the database?

How to get updates from a working server to an app if its not running (Android Studio)

I'm working on an app that is very simple (it's a chat app)
I have a server and Android users.
for example say we have 2 users, user_a and user_b.
user_a enters a chat room and sends "hi user_b" (user_b is registered to this chat room)
when user_a sends his message, it is also sent to the server.
I'd like to make a service that will be running always in the background even when the app isn't running. that service will check for new updates each time.
so I'd like user_b to receive the message, and it will appear as notification.
in order to do it my approach is to make a service that will continuesly run in the background. any suggestions?
The best way to do this is sending messages to your server, which will notify recipients via GCM in real-time. You need to create a gcm intent service so you can catch gcm messages and handle them properly in your app (build a notification and updating chat activity)
You can also broadcast the messages you receive from gcm notifications so you update your chat online (like all chat apps do…)
I recommend you to read about GCM and broadcast

Getting xmpp messages while app is in background in android

As the app disconnects it stops getting messages from xmpp server. For background notification purpose, I am using GCM service. Now, Just like WhatsApp I want my app too to receive the messages in background and save them in sqlite.
Is it necessary for this task that my app would always be connected to
xmpp server?
Will it not load the xmpp server Since, so many sessions the server
will have to keep alive?
Don't set keep alive for less then 10 minutes this will load the server.
When app is in the background then you have to send push notification via gcm for android and apns for iPhone. For this to implement you need to implement plugin on openfire.
1 up if you like the answer. Email me at cvofjaspreet#gmail.com I can provide you code for plugin also.

Categories

Resources