Android O:PHONE_STATE广播限制 [英] Android O : PHONE_STATE broadcast limitation

查看:205
本文介绍了Android O:PHONE_STATE广播限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试做一些与truecaller应用类似的事情,在该应用中,我的应用应该在呼叫挂断后显示屏幕。通过在清单文件中注册 android.intent.action.PHONE_STATE 隐式广播来实现这一点。

I have been trying to do something similar to truecaller app, where my app is supposed to show a screen after a call gets hung up. Was achieving this by registering android.intent.action.PHONE_STATE implicit broadcast in the manifest file.

但是如果 Android O广播限制,我正在尝试找出此用例的替代解决方案。

But it is not working if I change the app to target Android O, because of the Android O broadcast limitation, and I'm trying to figure out an alternative solution to this use case.

android文档中建议的替代解决方案:工作计划程序或注册服务上下文

Alternative solutions suggested in android docs: Job scheduler or register a service with context.

工作计划程序::由于 Job Scheduler 优化会导致接收回调的延迟。因此,如果在通话和轮询之后每隔几分钟显示我们的应用程序屏幕,每隔几秒钟就会显示一次我们的应用程序屏幕,则这会影响用户体验。

Job scheduler: Because of the Job scheduler optimizations there will be some delay to receive the callback. So it will affect the user experience if our app screen is shown a few min after the phone call and polling to check for new call logs every few seconds causes battery drain issue.

在Java中使用上下文注册服务:即使该应用未处于活动状态,我也希望该行为能够正常运行。如果系统终止了 Service ,这将无法正常工作。

Register service with context in Java: I want the behavior to work even if the app is not active or alive. This will not work if the system kills the Service.

注册前台服务 :这需要始终向用户显示通知,这将是对用户的垃圾邮件,并且24/7全天候运行服务会消耗大量资源,从而无法达到广播限制的整个目的。

Register a Foreground Service: This requires a notification to be shown to the user all the time, which would be spam the user, and running a service 24/7 consumes lots of resources which defeats the whole purpose of broadcast limitation.

请提出一个替代解决方案,以使用户体验保持不变。

Please suggest an alternate solution so that the user experience remains the same.

预先感谢

推荐答案

因为没有适当的解决方案,从Android O读取PHONE_STATE。我们可以寻求的最佳选择是从内容提供商。这样,就可以保持通话结束后显示屏幕(有几秒钟的延迟)的行为。

As there is NO proper solution to read the PHONE_STATE from Android O. The best alternative we can go for is to trigger a job on new call log entry from the content provider. By this, the behaviour is maintained of showing a screen(with a few sec of delay) after the call ends.

注意:缺点是我们无法获得的状态。电话(正在响铃或摘机等)。仅在将新的呼叫日志添加到系统数据库之后,才可以接收回叫。

NOTE : The disadvantage is we cannot get the state of the phone call(Ringing or off_the_hook etc.,). The call back will only be received after the new call log has been added to the System DB.

这篇关于Android O:PHONE_STATE广播限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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