расширить класс BroadcastReceiver, установить загрузку и затем добавить прослушиватель onReceive
TelephonyManager telephonymanager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener listener = new Listener();
telephonymanager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
код прослушивателя:
class Listener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stub
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
break;
case TelephonyManager.CALL_STATE_RINGING:
// do sth
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}