2

In my app I have to detect if the outgoing call is accepted or disconnected or ringing. I went through these posts:

But none of these posts give a proper answer. I used the Android internal class com.android.internal.telephony.CallManager, but I'm only getting whether the phone state is idle.

Community
  • 1
  • 1
Ekanta Swain
  • 473
  • 2
  • 13
  • 28

1 Answers1

0

Formally you cannot do that, as explained here, but there is a workaround that I'm using: You can save your last status and use it to identify when an outgoing call moves from off-hook to idle, which means that the call was hung up or accepted. So, to know which it is, you can check if the call still alive and if so you can tell that the call was answered and execute your code.

For example:

// 0 --> 1 || 0 --> 2
if (   laststate == TelephonyManager.CALL_STATE_IDLE
    && (   state == TelephonyManager.CALL_STATE_RINGING
        || state == TelephonyManager.CALL_STATE_OFFHOOK))
{
}
else if (state == TelephonyManager.CALL_STATE_IDLE)
{
}

if (   laststate == TelephonyManager.CALL_STATE_OFFHOOK
    && state == TelephonyManager.CALL_STATE_IDLE)
{
}

laststate = state;
Community
  • 1
  • 1
Jow
  • 181
  • 1
  • 5