Android (Lollipop) cannot detect ongoing phone call from second SIM

473 views Asked by At

I have a piece of code that makes phone calls and hangs up after a certain amount of time. I've managed to make calls from both SIMs (using different tricks for the 2nd SIM), however, Android does not seem to be able to detect whether the 2nd SIM is off-hook;

Take a look at this piece of code:

Class<?> c = Class.forName(telMgr.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService = (ITelephony)m.invoke(telMgr);
if (telephonyService.isOffhook()) { // DO SOMETHING }

If the first SIM makes the call, I get isOffHook() to be true, but from the second SIM, the phone is in progress, but I get false.

Is there a way to detect if I'm off-hook on both SIMs? Thanks

1

There are 1 answers

0
Hummus On

Thanks for the comments, but I have found a solution. Rather than use old methodology of retrieving the ITelephony "instance" from the TelephonyManager (I used this trick in older versions cause other ways were making me troubles), I use the TelephonyManager directly by calling getCallState(), and it seems informative and accurate for both SIMs. A code sample:

TelephonyManager telMgr = (TelephonyManager)(this.getMainContext()
                        .getSystemService(Context.TELEPHONY_SERVICE));
/* Making a call... */
if (telMgr.getCallState() != TelephonyManager.CALL_STATE_OFFHOOK) { /* Do your stuff */ }

Simple and straight forward. Working with my current 5.1 Lollipop version.