7

I want to display one dialog box after incoming call, so that I can run my application in background while receiving call.

How to catch that incoming call in android application???

Akshata
  • 271
  • 2
  • 7
  • 11

2 Answers2

7

In AndroidManifest.xml you shoud make a receiver:

<receiver android:name="IncomingCallInterceptor">                    
    <intent-filter>
         <action android:name="android.intent.action.PHONE_STATE"/>   
    </intent-filter>
</receiver>

and declare permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Then,

public class IncomingCallInterceptor extends BroadcastReceiver {


@Override 
public void onReceive(final Context context, Intent intent) {                                         
    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);                         


    if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {                                   

        // Phone is ringing

    }


}

}
defhlt
  • 1,775
  • 2
  • 17
  • 24
2

Maybe this broadcast intent is what you need ACTION_PHONE_STATE_CHANGED

hara
  • 3,274
  • 4
  • 37
  • 55