4

I would like to know if there is any way for an android APP to detect how much time does another person (not the device owner) takes to pick up a call. In other words, to measure the time between I dial a number and the other person picks it up. I want to create a chart like: John takes an average of 5 seconds to pick up a call, Jane an average of 8 seconds and so on.

Thanks!

Emmet Brown
  • 456
  • 6
  • 21

2 Answers2

3

Create a receiver for callstate, it will recieve every the phone is ringing, idle and in the call. I would get the system time when it starts ringing, and compare against it when the phone answers.

public void onReceive(Context context, Intent intent) {

String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
    //Phone ringing
    callTime = System.currentTimeMillis();

}else if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK){
    //Call answered
    answeredTime = System.currentTimeMillis();
    timeTaken = answeredTime - callTime;


}else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
    //Call rejected

}

}

This should be a start

RedChris
  • 523
  • 1
  • 8
  • 19
  • 1
    `STATE_RINGING` means your phone is ringing, not you dialed a number and the receiving phone is ringing. – Geobits Sep 30 '13 at 15:10
  • Your completely right, I meant STATE_OFF_HOOK which means, At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting. I'm not sure it would call OFF_HOOK twice in a row though, however you detect an outgoing call by receiving ACTION_NEW_OUTGOING_CALL. You can get the system time from there as well. – RedChris Sep 30 '13 at 15:27
0

There may be a way to do it using MediaRecorder, but I've read elsewhere that whether it works depends on the phone. This example records to a file, but you may be able to redirect to a stream and process the audio within your app.

There are other issues to keep in mind, though. Quoting a Lifehacker article:

[W]hen you're dealing with phone calls that aren't via VoIP, you run dangerously close to wiretapping laws, which can get complicated.

If you have the resources, it may be easier to redirect the call through VOIP and record from the VOIP server.

Edit: try this link out. It uses the TelephonyManager to check for the call state change from "ringing" to "off hook".

Community
  • 1
  • 1
nemec
  • 1,044
  • 9
  • 35
  • Right, the phone detects when someone picks up the call on the other side. My phone has haptic response. I would like to know if there is any way for an app to read that status. VoIP is not an option. – Emmet Brown Sep 30 '13 at 00:43
  • I edited my post with a link to another SO question that explains a better approach. – nemec Sep 30 '13 at 15:06