如果已经通话并且第二个呼叫者正在呼叫,如何不触发 PhoneStateListener.CALL_STATE_RINGING
我正在编写一个应用程序,可以自动接听电话。问题是,如果我已经在通话中并且有人正在响铃,那么它不应该应答。 有办法实现吗?
根据文档,如果我使用 TelephonyManager
检查状态,它将是 CALL_STATE_RINGING
而不是 CALL_STATE_OFFTHEHOOK
。
我是否必须添加一个在更改电话状态时设置为 true 的变量,以便我知道有正在进行的呼叫,或者是否有更好的解决方案?
谢谢!
/edit:我在没有 Modify_Phone_State
权限的情况下接听电话,所以这只是为了查明是否已经有通话正在进行。
I am programming an app, that automatically answers a call. The problem is, that it should not answer one if I am already in a call and someone is ringing.
Is there a way to achieve that?
According to the doc, if I check the status with TelephonyManager
it would be CALL_STATE_RINGING
and not CALL_STATE_OFFTHEHOOK
.
Do I have to add a variable that is set true on a changing Telephone state so I know that there is an ongoing call or is there a better solution?
Thanks!
/edit: I answer the call without the permission Modify_Phone_State
, so it is only about finding out if there is already a call ongoing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
跟踪呼叫状态是最好的方法,因为你的问题偏离了android标准。
你的问题没有官方答案,因为:
通过Android API,没有官方方法第三方应用程序提供商接听电话,因为
1:你必须使用未记录的 API。
2:请求 MODIFY_PHONE_STATE 权限仅适用于自 2.3 起的 root/系统签名应用程序
因此,如果您的问题存在有效(内置代码)工作答案,则它可能正式不适用于每个制造商/型号设备。
更多信息请访问如何授予 MODIFY_PHONE_STATE 权限适用于在 Gingerbread 上运行的应用
Tracking call state seams the best way, because your question is off the track of android standard.
There is no official answer to your question because :
By the Android API there is no official way for a third party application provider to answer to a phone call because
1 : you've to use undocumented API.
2 : request MODIFY_PHONE_STATE permission is only available for rooted/system signed application since 2.3
So if an efficient(build in code) working answer exist for your question, it may officially not working for every manufacturer/model devices.
more info at How to grant MODIFY_PHONE_STATE permission for apps ran on Gingerbread
好吧,显然没有办法解决这个问题,一旦状态变为
OFFTHEHOOK
(true),我就将布尔值存储在 SharedPreference 中。当状态更改为 IDLE 时,我将布尔值设置为 false。因此,这意味着,如果在有人已经呼叫时触发 RINGING,我会读出该变量为 true,然后放弃以下操作。
如果您想了解有关如何接听电话的更多信息,请查看自动应答项目
Okay, so as there is apparently no way to figure this out, I stored a Boolean in a SharedPreference as soon as the State goes to
OFFTHEHOOK
(true).When the state changes to
IDLE
, I set the Boolean to false. So this means, ifRINGING
is fired while someone is already calling, I read out that the variable is true, and then discard the following actions.For those who want more information on how to answer a call, have a look at the AutoAnswer Project