1. Download our Official Android App: Forums for Android!

Apps How to detect incoming call

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

  1. uaeHamed

    uaeHamed Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    May 22, 2011

    May 22, 2011
    20
    1
    16
    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?
     

    Advertisement

  2. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    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
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    May 22, 2011

    May 22, 2011
    20
    1
    16
    So my class will be a BroadcastReceiver class and on receive() it will implement my action?
     
  4. BitGriff

    BitGriff Lurker
    Rank:
    None
    Points:
    25
    Posts:
    7
    Joined:
    Feb 12, 2013

    Feb 12, 2013
    7
    0
    25
    Male
    BitGriff LLC
    Russian Federation, Tyumen
    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.
     

Share This Page

Loading...