How to show notification of an incoming call in an Android application

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

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

+6
android
source share
2 answers

In AndroidManifest.xml you create 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 } } } 
+6
source share

Perhaps this broadcast intent is what you need ACTION_PHONE_STATE_CHANGED

+2
source share

All Articles