17

How to check if a telephone call is currently active from a non-telephone app?

What API do I need to detect this?

Kara
  • 6,115
  • 16
  • 50
  • 57
linquize
  • 19,828
  • 10
  • 59
  • 83

1 Answers1

45

try this:

public boolean isCallActive(Context context){
   AudioManager manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
   return manager.getMode() == AudioManager.MODE_IN_CALL;
}
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
  • 6
    I would really prefer `return manager.getMode()==AudioManager.MODE_IN_CALL;` the rest is perfect, thanks! – jobbert Sep 08 '16 at 13:24
  • 1
    Works like charm. Thank you. +1 – Parth Anjaria Nov 11 '18 at 10:54
  • Nice!, to reduce code i would simply write: `return manager.getMode() == AudioManager.MODE_IN_CALL)` – htafoya Mar 26 '20 at 19:26
  • 2
    Just as a note, this doesn't work in call cases. If I have a call active and another waiting, I finish the call active and answer the one waiting, this won't say there was a period of time with no call active (after I finish the active one and before I answer the waiting one). It's always MODE_IN_CALL since the moment one call gets the phone to CALL_STATE_OFFHOOK until the phone goes to CALL_STATE_IDLE, no matter if I didn't answer the waiting call at all or not. Pity. – Edw590 Dec 23 '20 at 19:59