如何检测和管理来电(Android)?

发布于 2024-11-19 01:36:26 字数 122 浏览 2 评论 0原文

我想创建一个应用程序,可以检测来电并在一定数量的蜂鸣声(响铃)后启动我的自定义活动,我的意思是在 2 或 3 或 5 声蜂鸣声(响铃)后我的 activity 被触发。我该怎么做呢?

谢谢

I want to create an application that can detect incoming calls and start my custom activity after a certain number of beeps (rings), I mean after 2 or 3 or 5 beeps (rings) my activity is triggered. How can I do it?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

開玄 2024-11-26 01:36:26

我认为您无法计算自来电开始以来电话响了多少次。无法对单个铃声进行明确的测量,因为用户可以轻松地将铃声更改为不重复的曲调,例如歌曲。

然而,您可以做的是计算自呼叫到达以来所经过的时间。为 PHONE_STATE 设置一个 BroadcastReceiver(您需要清单中的相应权限才能接收事件)。收到 PHONE_STATE 附带的 EXTRA_STATE_RINGING 后,通过 AlarmManager 设置闹钟,该闹钟将触发 Service检查EXTRA_STATE_OFFHOOK(在接听电话时广播)是否在您的等待时间后广播。如果没有,那么您可以启动答录机。

我写了一个快速教程在我的网站中,了解如何捕获呼叫的到达(当电话响起时)、呼叫何时接听以及呼叫何时结束。

I don't think you can count the number of rings the phone made since the start of the incoming call. There can't be a definitive measure of a single ring because the user can easily change the ringtone to a non-repetitive tune, for example, a song.

What you can do, however, is count the amount of time that passed since the arrival of the call. Set up a BroadcastReceiver for PHONE_STATE (you will need the corresponding permission in the manifest to receive the event). Once you receive the EXTRA_STATE_RINGING that came with the PHONE_STATE, set an alarm via the AlarmManager that will fire a Service that checks if EXTRA_STATE_OFFHOOK (broadcast when the call is picked up) has been broadcast after your waiting time. If not, then you can start your answering machine.

I have written a quick tutorial in my website on how to catch the call's arrival (when the phone rings), when the call is picked up, and when it ends.

满意归宿 2024-11-26 01:36:26

我关于检测来电和去电的文章,包含分步说明:
在 Android 上检测来电和去电

当您检测到来电时,您可以启动一个计时器,间隔等于 beepInterval * beepCount。并在此计时器上启动活动。

My article about detecting incoming and outgoing calls, with the step-by-step instructions:
Detecting incoming and outgoing phone calls on Android

When you detect incoming call, you can start a timer, with interval equal to beepInterval * beepCount. And launch activity on this timer.

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