如何在 ITelephony 中终止来电

How to terminate an incoming call within ITelephony

我正在尝试断开来电但遇到此错误

 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文件?如果没有从 here 下载并将其添加到您的项目中。

你必须像这样添加文件

另外你的包名必须是com/android/internal/telephony/ITelephony.AIDL:

选中此tutorial 以实施 Aidl 文件