Kill a phone call programatically in Oreo

妖精的绣舞 提交于 2020-01-05 17:00:18

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/50227490/kill-a-phone-call-programatically-in-oreo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!