【发布时间】:2017-06-20 10:46:24
【问题描述】:
我正在尝试断开来电但遇到此错误
public interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
private void disconnectPhoneItelephony(Context context)
{
ITelephony telephonyService;
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
try
{
telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.endCall();
}
catch (Exception e)
{
e.printStackTrace();
Log.d("error", e.toString());
}
}
错误:
(java.lang.ClassCastException:com.android.internal.telephony.ITelephony$Stub$
Proxy cannot be cast to belllab.com.meetingmanager.ITelephony )
【问题讨论】:
-
检查导入的文件包名和你的。
-
包名正确
-
看看你的项目中是否添加了 ITelephony.AIDL 文件?如果你已经添加,那么你的包名必须是包名必须是 com/android/internal/telephony/ITelephony.AIDL
-
不,我没有添加那个文件
-
该文件的添加位置以及如何获取该文件
标签: android telephony telephonymanager