我正在开发 voip 应用程序。我执行有关后台服务信号的所有逻辑。当用户存在该应用程序时,我将停止该服务。在这种情况下,我没有连接到服务器。当我处于这种状态时,服务器正在发送推送通知 (FCM),我正在启动服务并为来电或消息创建通知。到目前为止一切都很好:)
我已经阅读了 Oreo 对后台服务的限制,并意识到现在我需要在显示通知的同时在前台启动服务。然后我想检查 Hangouts(google) 是如何做到的,当然,当收到消息时,他们正在后台运行该服务。我错过了什么吗?
谢谢
最佳答案
可见 Activity = 前景
When user exists the app I am stoping the service
如果这意味着该服务仅在您的应用程序对用户可见时才运行,那么该进程和服务实际上在前台,您应该不会遇到系统终止您的服务的任何问题:
An app is considered to be in the foreground if any of the following is true:
- It has a visible activity, whether the activity is started or paused.
收到 FCM = 前台
另外,收到高优先级的FCM消息会把你的app放到临时白名单中后台处理,到时候你有足够的时间做你的处理,或者你也可以在收到FCM后随时启动前台服务- 就像一个处理调用的服务,应该在运行时显示通知:
Under certain circumstances, a background app is placed on a temporary whitelist for several minutes. While an app is on the whitelist, it can launch services without limitation, and its background services are permitted to run. An app is placed on the whitelist when it handles a task that's visible to the user, such as:
- Handling a high-priority Firebase Cloud Messaging (FCM) message.
您的应用设计 - 通过接收优先级 FCM 处理传入调用,然后创建前台调用服务 - 似乎是合理的。
引用documentation这在这些主题上非常清楚。
关于android - 后台服务限制 Android 和 voip 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47696249/