Android 我无法按程序断开电话
我想在单击其他呼叫应用程序上的按钮时断开呼叫,但在中单击断开按钮时会引发异常…以下是我的代码: 主要活动:Android 我无法按程序断开电话,android,Android,我想在单击其他呼叫应用程序上的按钮时断开呼叫,但在中单击断开按钮时会引发异常…以下是我的代码: 主要活动: private void DisconnectOnGoingCall() { try{ TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); Class clazz = null;
private void DisconnectOnGoingCall() {
try{
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
Class clazz = null;
try {
clazz = Class.forName(telephonyManager.getClass().getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Method method = null;
try {
method = clazz.getDeclaredMethod("getITelephony");
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
method.setAccessible(true);
ITelephony telephonyService = null;
try {
telephonyService = (ITelephony) method.invoke(telephonyManager);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
telephonyService.endCall();
}catch (NullPointerException ignored){
}
ITelephony:
public interface ITelephony {
boolean endCall();
}
Logcat中生成的错误:
java.lang.ClassCastException: com.android.internal.telephony.ITelephony$Stub$Proxy cannot be cast to com.android.internal.smart_dectector.ITelephony
at com.android.internal.smart_dectector.MainActivity.DisconnectOnGoingCall(MainActivity.java:57)