Kill a phone call programatically in Oreo
Asked Answered
E

1

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

Expedite answered 8/5, 2018 at 6:47 Comment(1)
See this question: #47732225Deemster
H
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.

Hollishollister answered 11/7, 2019 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.