Incoming Phone Call Receiver

BroadcastReceiver

public class MyReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(final Context context, Intent intent) {
            Log.i("MyReceiver", "call state changed.... ");

//Tracking 2nd sim Mobile number
            String second_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
            String second_number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

            Log.i("MyReceiver", "call state changed.... "+second_number);
            Log.i("MyReceiver", "call state changed.... "+second_state);

            TelephonyManager mtelephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
            mtelephony.listen(new PhoneStateListener(){
                @Override
                public void onCallStateChanged(int state, String incomingNumber) {
                    Log.i("MyReceiver", "call state changed.... "+state);
                    super.onCallStateChanged(state, incomingNumber);

                    switch (state) {
                        case TelephonyManager.CALL_STATE_RINGING:
                            Log.d("MyReceiver", "I'm in " + state + " and the number is " + incomingNumber);
                            break;
                        default:
                            break;
                    }
                }
            },PhoneStateListener.LISTEN_CALL_STATE);
        }
}

From Activity

MyReceiver myReceiver = new MyReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(myReceiver, intentFilter);

Manifest.XML

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

Permissions

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

References