Recently, I've been trying to implement a way to detect if an outgoing call is answered or not?
I know that this is an old question in this forum. I've come across the whole useless solutions suggested by developer.
Tim S.'s answer has come cross using a hidden API that is authorized for only system applications to benefit from PRECISECALL_STATE_ACTIVE
leaving no choice to have an explicit state that shows if the call is answered for third party applications. The only available states that are available for 3rd party apps are provided by the telephony manager are CALL_STATE_RINGING
, CALL_STATE_OFFHOOK
, and CALL_STATE_IDLE
, which gives no clue to what i intended to do.
My question is, isn't there any walk around, for example to isolate the audio sources coming from the ear speakers, or away to access the call layout to extract the call timer in real time??
The code is shown below:
class Custom_PhoneState_Listener extends PhoneStateListener{
int state;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
//switch to isolate call states
switch(state)
{
case TelephonyManager.CALL_STATE_IDLE:
Log.d("call state:","CALL STATE IDLE");
state=0;
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d("call state:","CALL STATE RINGING");
state=1;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("call state:","CALL STATE OFFHOCK");
state=2;
MyFunction(); //the function should be executed once the call is answered
break;
default: Log.d("call state:","THERE IS NO STATE DETECTED");
}
}`