如果已经通话并且第二个呼叫者正在呼叫,如何不触发 PhoneStateListener.CALL_STATE_RINGING

发布于 2024-12-17 07:00:38 字数 360 浏览 1 评论 0原文

我正在编写一个应用程序,可以自动接听电话。问题是,如果我已经在通话中并且有人正在响铃,那么它不应该应答。 有办法实现吗?

根据文档,如果我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦中的蝴蝶 2024-12-24 07:00:38

跟踪呼叫状态是最好的方法,因为你的问题偏离了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

空宴 2024-12-24 07:00:38

好吧,显然没有办法解决这个问题,一旦状态变为 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, if RINGING 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文