简体   繁体   English

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

[英]How to detect and manage incoming call (Android)?

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.我想创建一个可以检测来电并在一定数量的哔声(响铃)后启动我的自定义活动的应用程序,我的意思是在 2 或 3 或 5 声哔声(响铃)后我的activity被触发。 How can I do it?我该怎么做?

Thanks谢谢

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).PHONE_STATE BroadcastReceiver您需要清单中的相应权限才能接收事件)。 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.一旦您收到 PHONE_STATE 附带的EXTRA_STATE_RINGING ,请通过PHONE_STATE设置一个警报,该AlarmManager将触发一个Service ,检查您的等待时间后是否已广播EXTRA_STATE_OFFHOOK (接听电话时广播)。 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.在我的网站上写了一个快速教程,介绍如何捕捉电话的到来(电话响铃时)、接听电话的时间以及结束的时间。

My article about detecting incoming and outgoing calls, with the step-by-step instructions: Detecting incoming and outgoing phone calls on Android我关于检测来电和去电的文章,并附有分步说明: 在 Android 上检测来电和去电

When you detect incoming call, you can start a timer, with interval equal to beepInterval * beepCount.当您检测到来电时,您可以启动一个计时器,其时间间隔等于 beepInterval * beepCount。 And launch activity on this timer.并在此计时器上启动活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM