1. Are you ready for the Galaxy S20? Here is everything we know so far!

How to detect incoming call

Discussion in 'Android Development' started by uaeHamed, May 25, 2011.

  1. uaeHamed

    uaeHamed Newbie
    Thread Starter

    Hi. Im working on an application that does something during a call. So I understand I need to use a service. But how does my application detect that a call is incoming or the call is answered or whatever before I launch the service?
     


  2. miXer

    miXer Android Enthusiast

    To listen for change in calls you can use a broadcast with action: android.intent.action.PHONE_STATE:
    Code (Text):
    1. <receiver android:name=".CallReceiver">
    2.             <intent-filter>
    3.                 <action android:name="android.intent.action.PHONE_STATE" />
    4.             </intent-filter>
    5.         </receiver>
    And you can check the EXTRA_STATE in the intent given with the broadcast:
    Code (Text):
    1. String callState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
     
    uaeHamed likes this.
  3. uaeHamed

    uaeHamed Newbie
    Thread Starter

    So my class will be a BroadcastReceiver class and on receive() it will implement my action?
     
  4. BitGriff

    BitGriff Lurker

    I wrote an article with detailed instructions, how to make it.

    I used broadcast receiver for outgoing calls, and PhoneStateListener for incoming. Calls detection code running in service.

    Article include detailed source code. You can modify it for your own needs.

    You can see it here:
    BitGriff: Detecting incoming and outgoing phone calls on Android.
     
Loading...

Share This Page

Loading...