You need a BroadcastReceiver:
public class IncomingBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { MyLog.d("IncomingBroadcastReceiver: onReceive: "); String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); MyLog.d("IncomingBroadcastReceiver: onReceive: " + state); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { Intent i = new Intent(context, IncomingCallActivity.class); i.putExtras(intent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } }
And register it in the manifest on <action android:name="android.intent.action.PHONE_STATE"></action> .
Then create an action like this:
public class IncomingCallActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { MyLog.d("IncomingCallActivity: onCreate: ");
which has this layout:
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical|center_horizontal" android:text="text" android:windowBackground="@android:color/transparent" android:windowIsTranslucent="true" android:windowAnimationStyle="@android:style/Animation.Translucent"></TextView>
This will lead to a translucent dialogical action on top of the incoming call screen, which allows the user to answer the call (does not interfere with touch events).
source share