How to detect and manage incoming call (Android)?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 20:43:35

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!