Whatsapp或电报之类的应用程序如何监听Android上的来电/消息事件? [英] How does apps like Whatsapp or telegram listen to the incoming call/message events on Android?

查看:259
本文介绍了Whatsapp或电报之类的应用程序如何监听Android上的来电/消息事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个VoIP呼叫应用程序,该应用程序与服务器保持持久连接以监听所有来电.为此,我实施了后台服务.

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. 将服务转换为JobService并让android对其进行调度

这样做,我的应用停止后将无法接听电话

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

在前台服务中运行操作

对于某些用户而言,在通知栏中看到持续的通知很烦人.因此,上述这些选项对我来说无法为Oreo修复我的代码.

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.

WhatsApp如何在Android(从奥利奥(Oreo)开始)中获得传入(VOIP)呼叫,围绕

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

推荐答案

我假设您正在使用SIP建立连接并发起呼叫.如果没有服务不断重新发送REGISTER,则服务器将其发送时,该应用程序将不会收到INVITE.

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.

解决此问题的方法是所谓的推送通知策略".它的工作原理如下:当服务器发送INVITE时,它还会向您的应用程序发送FCM通知,这将唤醒您的应用程序,然后将REGISTER发送到您的服务器,服务器将返回的呼叫分叉到您的应用程序. 这是一个可以更好地解释该策略的视频

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

这篇关于Whatsapp或电报之类的应用程序如何监听Android上的来电/消息事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆