7

I am trying to detect when a user answers the phone. My app dials the phone number but without seeing if the user answered I can't perform a key function I need. It seems you were able to do this in version 5 and up as seen in this post, but I can't figure out how to do it. I know someone must have come up with a work-around because as one person previously stated the call timer starts once the user answers so there must be a way to detect it. This question has been posted many times, but no one posts a CORRECT answer.

It seems the answer lies in Tim S. answer here:

Cannot detect when outgoing call is answered in Android

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

<receiver android:name=".listener.OutCallLogger">
    <intent-filter>
        <action android:name="android.intent.action.PRECISE_CALL_STATE" />
    </intent-filter>
</receiver>
public class OutCallLogger extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        switch (intent.getIntExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, -2) {
            case PreciseCallState.PRECISE_CALL_STATE_IDLE:
                Log.d(This.LOG_TAG, "IDLE");
                break;
            case PreciseCallState.PRECISE_CALL_STATE_DIALING:
                Log.d(This.LOG_TAG, "DIALING");
                break;
            case PreciseCallState.PRECISE_CALL_STATE_ALERTING:
                Log.d(This.LOG_TAG, "ALERTING");
                break;
            case PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
                Log.d(This.LOG_TAG, "ACTIVE");
                break;
        }
    }
}
Community
  • 1
  • 1

1 Answers1

0

I don't think it's possible without actually checking the ringing tone for changes. I'm going to give an idea on how it could possibly be done because nobody has given any answers yet.

On both of my current phones(one is root, one is not), the number is dialed and then the 'call timer' starts. The phone itself appears to not even know when the call has been answered, only when it has ended. I don't believe there is a simple way of doing this.

If you compare each individual ring tone and compare the spacing to make sure that the call is still ringing, you'll know that it hasn't been answered. Once you detect noise that shouldn't be there, you can assume that someone has answered and said "Hello" or whatever(hopefully not at the exact same time as a ring tone). You already know how to detect if the call has ended. I have no idea one what type of sound APIs someone would start with on a project like this.