简体   繁体   English

如何终止ITelephony内的来电

[英]How to terminate an incoming call within ITelephony

i am trying to disconnect incoming call but facing this error 我试图断开来电但面临这个错误

 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());
    }
} 

error: 错误:

(java.lang.ClassCastException:com.android.internal.telephony.ITelephony$Stub$
Proxy cannot be cast to belllab.com.meetingmanager.ITelephony )
telephonyService = (ITelephony) m.invoke(telephony);

This is not possible because m.invoke(telephony) does not return a sub class of ITelephony nor ITelephony itself, so you cannot cast it. 这是不可能的,因为m.invoke(telephony)不会返回ITelephony的子类,也不会返回ITelephony本身,因此您无法ITelephony它。

As you can see m.invoke(telephony) returns ITelephoney in com.android.internal.telephony package, but you are using ITelephoney in belllab.com.meetingmanager package. 正如你所看到m.invoke(telephony)返回ITelephoneycom.android.internal.telephony包,但使用的是ITelephoneybelllab.com.meetingmanager包。

If you have added ITelephony.AIDL file in your project? 如果您在项目中添加了ITelephony.AIDL文件? If not download from here and add it to your project. 如果没有从这里下载并将其添加到您的项目中。

You have to add the file like this 你必须像这样添加文件

在此输入图像描述

Also then your package name must be com/android/internal/telephony/ITelephony.AIDL: 此外,您的包名必须是com / android / internal / telephony / ITelephony.AIDL:

Check this tutorial to implement Aidl file 查看本教程以实现Aidl文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM