Это то, что я сделал
Файл манифеста :
<receiver android:name="com.xxx.xxx.zzz.IncomingCallReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>
полей в моих BroadcastReceiver (IncomingCallReceiver)
private static String previousCallingNumber = null;
private static String previousState = null;
private String RINGING = TelephonyManager.EXTRA_STATE_RINGING;
private String OFFHOOOK = TelephonyManager.EXTRA_STATE_OFFHOOK;
private String IDLE = TelephonyManager.EXTRA_STATE_IDLE;
public void onReceive(final Context context,Intent intent) {
final Bundle extras = intent.getExtras();
String state= null;
if (extras != null)
{
state = extras.getString(TelephonyManager.EXTRA_STATE);
}
/**
* This part of the code records that a call was recieved/attended or missed.
*
*/
else if (state!=null && state.equals(OFFHOOOK))
{
if(previousState!=null)
{
if(previousState.equals(RINGING) && previousCallingNumber!=null)
{
/**
* received call, the ringing call has been attended.
*/
String msisdn = MSISDNPreFixHandler.fixMsisdn(previousCallingNumber);
Log.i("IncomingCallReceiver", "Incoming Received Call Saved: "+msisdn);
}
}
/**
* Else the Incoming Call receiver is triggered when an outgoing call is made.
*
*/
}
else if (state!=null && state.equals(IDLE))
{
String incomingNumberForMissedCall = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
String msisdn = MSISDNPreFixHandler.fixMsisdn(incomingNumberForMissedCall);
if(incomingNumberForMissedCall!=null)
{
/**
* missed call, the ringing call has been missed.
*/
Log.i("IncomingCallReceiver", "Missed Call Saved: "+msisdn);
}
}
/**
* Very important to keep the previous state & number in cache ,
* as through it we can recognize the received attended call.
*
*/
previousState = state;
previousCallingNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
}