3

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

ngrashia
  • 9,869
  • 5
  • 43
  • 58
Mr.James
  • 376
  • 2
  • 8
  • 25
  • im sorry I dont not understand your question. could you re word it or give an example. – RMT Jul 07 '11 at 12:47
  • Okay dude , i want to speak clearly , well i want to make a answering machine and i want to when anyone call my phone after 2 or 3 beep my activity will be start , how can do it? – Mr.James Jul 07 '11 at 12:50
  • 2
    @Pars - I'm including a very good SO link that should help you with this task. Check it out - http://stackoverflow.com/questions/6036295/not-able-to-get-the-telephonymanager-call-state-ringing. – Perception Jul 07 '11 at 13:29
  • You want to block the Calls? Or Just want to start an Activity/Service while Incoming call arrives? – Vaibhav Jani Jul 30 '11 at 08:49
  • @Vaibhav Jani start an Activity/Service while Incoming call arrives – Mr.James Jul 30 '11 at 22:20
  • 1
    @Pars http://stackoverflow.com/questions/5948961/how-to-know-whether-i-am-in-a-call-on-android/5949116#5949116 – Vaibhav Jani Aug 01 '11 at 03:34

2 Answers2

4

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.

Matthew Quiros
  • 13,385
  • 12
  • 87
  • 132
4

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.

  • Thanks for posting your answer! Please be sure to read the [FAQ on Self-Promotion](http://stackoverflow.com/faq#promotion) carefully. Of particular note, please keep in mind what the FAQ says about if the majority of your posts contain links to your website. – Andrew Barber Feb 17 '13 at 07:43