Rejecting Incoming call in android

In order to intercept your call you just have to:
1. Make a package named. com.android.internal.telephony;
2. In this package make a interface file named ITelephony.
and write this code in that interface file.

boolean endCall();
void answerRingingCall();
void silenceRinger();

Now in your class where you want to intercept the call extend that class to BroadcastReceiver and in onReceive()function write the following code.

TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
   try {
     Class c = Class.forName(tm.getClass().getName());
     Method m = c.getDeclaredMethod("getITelephony");
     m.setAccessible(true);
     telephonyService = (ITelephony) m.invoke(tm);
     Bundle bundle = intent.getExtras();
     String phoneNumber = bundle.getString("incoming_number");
     Log.d("INCOMING", phoneNumber);
     if ((phoneNumber != null)) { 
        telephonyService.endCall();
        Log.d("HANG UP", phoneNumber);
     }

   } catch (Exception e) {
     e.printStackTrace();
   }

Thats it.

Leave a Comment