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;
}
}
}