Android (Lollipop) cannot detect current phone call from second SIM
I have a piece of code that makes phone calls and freezes after a certain amount of time. I was able to make calls from both SIMs (using different 2nd SIM tricks), however Android doesn't seem to be able to tell if the 2nd SIM is disabled;
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 system makes a call, I get isOffHook()
like true
, but from the second SIM, the phone runs, but I get false
.
Is there a way to determine if I can pick up the phone on both SIMs? Thanks to
source to share
Thanks for the comments, but I found a solution. Instead of using the old methodology to extract ITelephony
"instance" from TelephonyManager
(I used this trick in older versions because other ways were causing me problems), I use directly by TelephonyManager
calling getCallState()
and it seems informative and accurate for both SIMs . Sample code:
TelephonyManager telMgr = (TelephonyManager)(this.getMainContext()
.getSystemService(Context.TELEPHONY_SERVICE));
/* Making a call... */
if (telMgr.getCallState() != TelephonyManager.CALL_STATE_OFFHOOK) { /* Do your stuff */ }
Simple and straightforward. Working with my current version of Lollipop 5.1.
source to share