I'm not sure whether I understand your question. But you can use a broadcast receiver to listen to the action "android.intent.action.PHONE_STATE"
//register incoming call receiver
IntentFilter phonestateFilter = new IntentFilter("android.intent.action.PHONE_STATE");
registerReceiver(phonestateReceiver, phonestateFilter);
then in your receiver you can check whether the phone state is the following:
TelephonyManager.EXTRA_STATE_RINGING
TelephonyManager.EXTRA_STATE_OFFHOOK
TelephonyManager.EXTRA_STATE_IDLE
public void onReceive(Context context, Intent intent){
if (intent.getAction().equals("android.intent.action.PHONE_STATE")){
phoneState = bundle.getString(EXTRA_STATE);
if(phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
// the user is offhook now..
//get time
Date time = new Date();
}
}
However, outgoing call has its own intent action, which is "android.intent.action.NEW_OUTGOING_CALL", which requires another receiver.
In other words, you first receive outgoing call intent, and then receive the phone_state intent, for which you want to capture the "TelephonyManager.EXTRA_STATE_OFFHOOK"
To differentiate the offhook caused by outgoing calls from by incoming calls, you need to check whether you have ever received "TelephonyManager.EXTRA_STATE_RINGING". If not, that's caused by outgoing call. If yes, that's an incoming call.
Hope this helps you.
}