public boolean killCall(Context context) { try { // Get the boring old TelephonyManager TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); // Get the getITelephony() method Class classTelephony = Class.forName(telephonyManager.getClass().getName()); Method methodGetITelephony = classTelephony.getDeclaredMethod("getITelephony"); // Ignore that the method is supposed to be private methodGetITelephony.setAccessible(true); // Invoke getITelephony() to get the ITelephony interface Object telephonyInterface = methodGetITelephony.invoke(telephonyManager); // Get the endCall method from ITelephony Class telephonyInterfaceClass = Class.forName(telephonyInterface.getClass().getName()); Method methodEndCall = telephonyInterfaceClass.getDeclaredMethod("endCall"); // Invoke endCall() methodEndCall.invoke(telephonyInterface); } catch (Exception ex) { // Many things can go wrong with reflection calls Log.d(TAG,"PhoneStateReceiver **" + ex.toString()); return false; } return true; }
public static bool KillCall(Context c) { try { TelephonyManager tm = (TelephonyManager)c.GetSystemService(Context.TelephonyService); Type tp = tm.GetType(); System.Reflection.MethodInfo mi = tp.GetMethod("getITelephony", System.Reflection.BindingFlags.NonPublic); Type telephonyInter = mi.Invoke(tm, null).GetType().GetInterfaces().Single(e => e.Name == "ITelephony"); System.Reflection.MethodInfo mo = telephonyInter.GetMethod("endCall"); mo.Invoke(telephonyInter, null); } catch (Exception ex) { Toast.MakeText(c, ex.Message, ToastLength.Long).Show(); return false; } return true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)