Peter Peter - 2 months ago 19
Java Question

How to detect "in call mode" android java

I'm trying to detect mode when we in call. I'm using most popular example with broadcast and telephonyManager.

But there are only 3 states.

String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){

}
if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){

}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){

}


after some tests i found that :

1) when incoming call - than i see state = RINGING
- accept call from this state = OFFHOOK

2) but when im do outgoing call - state = OFFHOOK , and when another "me" on other side accept call - state still = OFFHOOK.

How to correctly detect IN_CALL_MODE (mean im speaking at current time ). ?
Can any help ?

Answer Source

How about using AudioManager??

AudioManager manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
if(manager.getMode()==AudioManager.MODE_IN_CALL){
    return true;    // Active call
}
else {
    return false;
}