Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does apps like Whatsapp or telegram listen to the incoming call/message events on Android?

I built a VoIP calling app which maintains a persistent connection with the server to listen to any incoming calls. I implemented a background service to do this.

But since Oreo, this running code is now broken because of the introduction of Background Execution Limits

After looking into forums, I found that some people are suggesting

  1. Convert Service to JobService and let android schedule it

    Doing so, my app won't be able to receive calls when it is stopped

  2. Run your operations in foreground services

    It is annoying for some users to see a constant notification in the notification bar. So these above-mentioned options aren't working for me to fix my code for Oreo.

How does WhatsApp get the incoming (VOIP) call in Android (Oreo onwards) working around the Background Execution Limits?

like image 238
Kantajit Avatar asked Jul 15 '19 08:07

Kantajit


People also ask

What is the difference between Telegram and WhatsApp?

Telegram better than WhatsApp for the following reasons Username feature − Without mobile number we can communicate with user with user name in telegram whereas in WhatsApp we cannot communicate with user name, mobile number is must. Secret chat available in telegram. Telegram supports both Voice calls & Video calls.

How does Telegram app works?

Unlike WhatsApp, Telegram is a cloud-based messenger with seamless sync. As a result, you can access your messages from several devices at once, including tablets and computers, and share an unlimited number of photos, videos and files (doc, zip, mp3, etc.) of up to 2 GB each.

Why use Telegram over WhatsApp?

Users can send any kind of file through Telegram. WhatsApp limits video, images & document type files which is very difficult for a good number of users. Users on telegram can log in on multiple devices at the same time and able to receive messages on all devices. They can remember their sessions on even browsers too.


2 Answers

(Sticky) foreground services are not affected by the restrictions. So you could use one those as replacement for background services on Oreo.

But foreground services have two disadvantages: They are less likely killed by the system in order to reclaim resources compared to background services, and hence affects the Android system's self-healing capability. And they require you to display a permanent notification. But Users are able to suppress the notification, somewhat mitigating this disadvantage.

like image 196
Flow Avatar answered Oct 11 '22 11:10

Flow


I am assuming that you are using SIP to establish the connection and initiate calls. Without a service constantly re-sending REGISTERs, the app doesn't receive INVITEs when the server sends them.

A workaround for this problem is what is called the "push notification strategy". It works as follows, when the server sends a INVITE, it also sends an FCM notification to your app, This wakes up your app which then sends a REGISTER to your server, which in return forks the call to your app. Here is a video that better explains this strategy

like image 34
user8127814 Avatar answered Oct 11 '22 13:10

user8127814