【发布时间】:2017-09-12 18:00:19
【问题描述】:
我正在使用下一个代码:
public void PhoneCallEnd(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
String error=ex.toString();
Toast.makeText(context, "error: "+ error , Toast.LENGTH_LONG).show();
txtHome.setText("error: "+ error);//cambio el contenido del TextView
}
}
问题是我得到下一个错误“java.lang.reflect.invocationTargetException”
“methodEndCall.invoke(telephonyInterface);”行中的应用程序崩溃
你能告诉我拒绝当前通话的正确方法吗?
【问题讨论】:
-
你能显示你的堆栈跟踪吗?
-
我怎样才能看到它?
-
复制 java.lang.reflect.invocationTargetException 的整个错误日志
-
错误是java.lang.SecurityException:用户10123和当前进程都没有android.permission.CALL_PHONE。
标签: android phone-call