2

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 are calling has answered. Looking through the forums this seems to be a tough and perhaps unanswered question. I'd really appreciate any insight into this.

In my searching the best I could find was in: Android : How to get a state that the outgoing call has been answered? @PattabiRaman said: "instead of detecting the outgoing call connection state, it is easy to get the duration of the last dialed call." Does he mean that one should get the duration of the last dialed call as the call is in progress? And when that duration goes over 0 then you know?

Community
  • 1
  • 1
user1585675
  • 21
  • 1
  • 3

2 Answers2

1

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.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • Thanks! I had no idea one could access Android's internal classes. – user1585675 Aug 30 '12 at 03:59
  • Hi above soulution Not giving permission to access internal class as CallManager . anyone have idea how to resolve this thing ? – aftab Dec 16 '12 at 07:08
  • Make sure you have the permissions. I added them above. – Johann Mar 05 '13 at 15:15
  • 3
    However, requesting the method "getActiveFgCallState" is working, the state never equals "ACTIVE", but equals "IDLE" even the call is connected. I tried polling the state multiple times during the call but no luck... (referring Galaxy Nexus S2 [GT-I9100], Android 4.1.2) – Sney Aug 06 '13 at 14:15
  • 3
    I confirm the problem: always "IDLE" on my phone – 18446744073709551615 Jun 08 '15 at 14:07
0

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