Try this in kotlin
In call i am using the timer for update the call time .I use the code inside the timer
val am = context!!.getSystemService(Context.AUDIO_SERVICE) as AudioManager
val mode = am.mode
if (AudioManager.MODE_IN_CALL == mode) {
// device is in a telephony call
} else if (AudioManager.MODE_IN_COMMUNICATION == mode) {
Log.e("MODE -","IN_COMMUNICATION")
// device is in communiation mode, i.e. in a VoIP or video call
} else if (AudioManager.MODE_RINGTONE == mode) {
// device is in ringing mode, some incoming is being signalled
if(AttendMeetingActivity.meetingManager!=null){
AttendMeetingActivity.meetingManager!!.onIncomingCall()
}else if( IncomingCallActivity.callControlManager!=null){
IncomingCallActivity!!.callControlManager!!.doHangUpCall()
}
} else {
// device is in normal mode, no incoming and no audio being played
}