How to programmatically end a call on 2.3+?

Before Android 2.2, I know that I can use reflection and end the call through getITelephony.

However, starting from version 2.3, this does not work anymore, because even if you grant MODIFY_PHONE_STATE permission for your application, now it is only permission for the system application:

However, this is possible because many applications on the google gaming market do an excellent job with ICS, like

https://play.google.com/store/apps/details?id=com.androminigsm.fscifree&hl=en

So the question is, how do they do it? I know that I can pick up a call using a simulated headset hook, but I cannot figure out how to end a call.

Thank.

+11
android
Apr 7 2018-12-12T00:
source share
3 answers

After a long search for the soul, I understand something really, really, really dumb. On the plus side, none of StackOverflow noticed this either. MODIFY_PHONE_STATE no longer works on silenceRinger () since version 2.3+, but endCall is just fine.

So the solution is to comment on the silentRinger () call.

I can't believe I spent a week on this! I will try to update other questions, since there seem to be tons of errors on SO, as "it’s impossible to use reflection to end calls anymore."

+18
Apr 7 2018-12-21T00:
source share

The call (), endcall () functions work fine for me as well. But there is another way that works without using iTelephony.aidl. Its published in this post. BTW I think google already knows, but for some reason they did nothing with the rest of the features, which are good !!!

http://androidbridge.blogspot.com/2011/05/how-to-answer-incoming-call-in-android.html

+3
Jul 28 '12 at 20:20
source share

private void endCall (final row time reduction) {

TelephonyManager telephony = (TelephonyManager) srvs .getSystemService(Context.TELEPHONY_SERVICE); Class c; final com.android.internal.telephony.ITelephony telephonyService; try { c = Class.forName("android.telephony.TelephonyManager");//telephony.getClass().getName()); Log.i("TelephonyClass Name", telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); telephonyService = (ITelephony) m.invoke(telephony); TimerTask task = new TimerTask() { @Override public void run() { try { if (telephonyService.isIdle() || telephonyService.isOffhook() || telephonyService.isRinging()) telephonyService.endCall(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; long delay = Integer.parseInt(cutofftime) * 1000; new Timer().schedule(task, delay); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 
+1
Jan 13 '14 at 10:50
source share



All Articles