1

I am using this method to end a call in android

 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.getCause().getStackTrace());
        return false;
    }
    return true;
}

This does work before Oreo but does not working on android oreo any idea what is missing.

Best Regards: Ali

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ali Akram
  • 4,803
  • 3
  • 29
  • 38
  • See this question: https://stackoverflow.com/questions/47731725/how-to-end-an-incoming-call-programatically-on-android-8-0-oreo – NoHarmDan Aug 07 '18 at 11:15

1 Answers1

0

I do your code and follow the explain: End call in android programmatically

add the following permission

<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" />

then it's working very well, my code is running on android oreo version.

Kevin
  • 1
  • 1