You do not need to be a system application. First, create the com.android.internal.telephony package in your project and put it in a file called " ITelephony.aidl ":
package com.android.internal.telephony; interface ITelephony { boolean endCall(); void answerRingingCall(); void silenceRinger(); }
Once you have this, you can use this code to end the call:
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); Class clazz = Class.forName(telephonyManager.getClass().getName()); Method method = clazz.getDeclaredMethod("getITelephony"); method.setAccessible(true); ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager); telephonyService.endCall();
You can use this inside PhoneStateListener, for example. For this to work, you need permissions in the manifest:
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
Edit: sorry for the awful formatting, I still canβt figure out how to make code blocks correctly here: /
bgse Aug 05 '13 at 18:44 2013-08-05 18:44
source share