1

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 )
bofredo
  • 2,348
  • 6
  • 32
  • 51
Hamza
  • 251
  • 3
  • 14

1 Answers1

0

If you have added ITelephony.AIDL file in your project? If not download from here and add it to your project.

You have to add the file like this

enter image description here

Also then your package name must be com/android/internal/telephony/ITelephony.AIDL:

Check this tutorial to implement Aidl file

Rameshbabu
  • 611
  • 2
  • 7
  • 21