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

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
Convert Service to JobService and let android schedule it
Doing so, my app won't be able to receive calls when it is stopped
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?

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

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

There are two options:
use platform push services (APNS or FCM)
maintain persistent socket connection and exclude application from battery optimisations.

Related

How to keep streaming if initial client loses connection?

I'm working on an app that streams out multiple presenters via the Agora Live Streaming protocol. Everything works great so long as the person who started the live stream stays connected, however if they lose internet, the stream stops, even if other presenters are still online.
Is there a way to tell the live stream to keep going until "stop live streaming" is called (or all presenters are offline)? My code can handle updating the transcoding config (e.g. video layout) when they go offline.
After multiple discussions with Agora Support, it appears the answer is no, if only using the web SDK, however they are introducing a new server side feature to make this possible.
It's currently in beta, so you'll have to ask Agora Support to enable it for your account, but once you've done so you can create and update an RTMP converter via their server side API instead of relying on the client SDK to manage the stream: https://docs-preprod.agora.io/en/Interactive%20Broadcast/streaming_restful
I'm assuming you're using startLiveStreaming method using the Agora Web SDK. You can attach event listeners on all hosts to listen for primary host's online status, in case the primary host (the host that calls the start method) goes offline - a secondary host can call the start (and transcode) method.
You can also use Agora RTM to signal this status.

Keep react-native application alive on android

I work on a mobile application and use MQTT (javascript paho client) for push notification. But after user or android close application ,MQTT socket has been disconnected and cannot receive notifications. So, I need to make a service to keep socket alive. How can I make a service by react-native?
I am using react-native-background-job for a similar use case. This library allows you to run a background job that will run periodically, but for this use case the important feature is that if you pass a alwaysRunning parameter when scheduling the job, the app will keep running in the background even if the user closes it.

ios 7 fetch offline message from xmpp server

I am developing chat application using XMPP protocol.
My development target is iOS 7.0
Every think is working fine user can able to communicate only when they are online.
But I want to notify user message has come when they are offline.
I have tried iphone XMPP App run background
But it doesn’t work for me.
First think it is possible or not?
Using what VIOP, background fetch or some other way?
If yes please let me know. how?.
The thread you are referring mention declaring that your app is a VoIP app to be allowed to constantly run in background.
It is technically possible but has two drawbacks:
If your application does not do voip, Apple will reject it (as misleading).
Battery consumption will be excessive as you will stay connected.
The state of the art is to fallback to Apple push notification service when the TCP connection between the client and the server is not established. This is battery efficient and provide a very good way to notify the user of new messages.

iOS Inter App Communication in Background

There is a platform application which connects to the remote server and stores required information in its local repository, that is in CoreData. I want to develop my application over this platform app. Since it is not possible to access its local storage, I have to communicate with it somehow. I am able to send/receive data using URL Schemes; however it's frustrating for user to switch between apps constantly.
Is it possible to communicate with another application via URL Schemes (or any other way) without bringing it to foreground?
With few exceptions, such as receiving CoreLocation data in the background or being notified to wake up by a local notification, it is not possible in iOS for an application to "run in the background"
This is a pretty common query on Stack Overflow, the official iOS reply can be found here
There are SO articles here and here.
Background data exchange is however not going to be a thing as there are restrictions on background app rules (so the URL transfer is going to foreground your second app)

C2DM Behavior over Wifi and 3G

I'm developing an app which relies on C2DM to be notified of some new data to be fetched from a REST service. I have successfully implemented the C2DM android feature, but the behavior over Wifi is different from the connection over 3G. The messages are received instantly over 3G, but I have to manually turn Wifi off and on to have a "grace period" of ~1 min in which I receive them instantly.
My question is: Is there any way I can programmatically restart the connection, or trigger the notification fetch?
EDIT:
I've implemented an AsyncTask that periodically "reassociates" the connection to the access point (using WifiManager.reassociate()) every minute and a half. Not so sure about the correctness of this solution, though.
I've seen similar issues. It seems that under some circumstances C2DM messages are not delivered over wifi connections, when they are over 3G. On a related note I've also seen Android devices "drop" the push connection, so messages are not delivered (in my case the solution can be to put the device in airplane mode and then turn the network back on).
This reinforces the fact that all applications that use C2DM should be built so that even if push messaging fails, the app still works (even if messages/updates are slower because there's occasional polling to the server)
I wouldn't personally want to mess with the wifi connection as that's something that may cause problems for the user.