I use the following code to handle incoming calls from within a service. It works perfectly when i invode the endCall method (My phone's Android Version is ICS). But when I invoke the answerRingingCall method i get an exception for not having permission to modify phone state. I know that Google revoked this permission at one point but since i can invoke the end call method what is the explanation for not being able to invoke the answer call method as well? I mean..both methods modify the phone's state, so what's up? Is there a way to fix this?
try { TelephonyManager tm = (TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE); Class c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); Object telephonyService = m.invoke(tm); // Get the internal ITelephony object c = Class.forName(telephonyService.getClass().getName()); // Get its class m = c.getDeclaredMethod("endCall"); // Get the "endCall()" method m.setAccessible(true); // Make it accessible m.invoke(telephonyService); // invoke endCall() } catch (Exception e) { Log.w("exception",e); }