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
Thanks for the comments, but I have found a solution. Rather than use old methodology of retrieving the
ITelephony
"instance" from theTelephonyManager
(I used this trick in older versions cause other ways were making me troubles), I use theTelephonyManager
directly by callinggetCallState()
, and it seems informative and accurate for both SIMs. A code sample:Simple and straight forward. Working with my current 5.1 Lollipop version.