Android detecting when lines have been connected during an outgoing call

后端 未结 2 803
独厮守ぢ
独厮守ぢ 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.

    0 讨论(0)
  • 2020-12-17 07:53

    I have looked into the code. It will always give null unless you instantiate a Phone object and set it as default Phone. But instantiating it needs some System permissions allowed only to system aps.

    By using this method: com.android.internal.telephony.PhoneFactory# public static void makeDefaultPhones(Context context) {

    http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r1.2/com/android/internal/telephony/PhoneFactory.java

    0 讨论(0)
提交回复
热议问题