Android detecting when lines have been connected during an outgoing call

后端 未结 2 813
独厮守ぢ
独厮守ぢ 2020-12-17 07:28

Just a quick background I\'m Running CM7 on a rooted Nexus one. I am trying to detect when an outgoing call is actually connected: has stopped ringing and the person you ar

2条回答
  •  無奈伤痛
    2020-12-17 07:42

    The class com.android.internal.telephony.CallManager should have information about when the call actually is answered. It has a public static method getInstance() which returns the CallManager instance, and a public method getActiveFgCallState() which returns the current call state as a Call.State enum.
    So in theory something like this might work:

    Method getFgState = null;
    Object cm = null;
    
    try {
      Class cmDesc = Class.forName("com.android.internal.telephony.CallManager");
      Method getCM = cmDesc.getMethod("getInstance");
      getFgState = cmDesc.getMethod("getActiveFgCallState");
      cm = getCM.invoke(null);
    } catch (Exception e) {
      e.printStackTrace();
    }
    

    And then repeatedly poll the state:

    Object state = getFgState.invoke(cm);
    if (state.toString().equals("IDLE")) {
      ...
    } else if (state.toString().equals("ACTIVE")) {
      // If the previous state wasn't "ACTIVE" then the
      // call has been established.
    }
    

    I haven't verified that this actually works. And even if it does you'll have to keep in mind that the API could change, since this isn't something that app developers are supposed to rely on.

提交回复
热议问题