title: Incoming Call Blocking in Android
body: <p>I am able to block incoming calls in android but problems it rings for fraction of seconds before disconnection of time. How can i directly disconnect phone without single ringing?</p>
  
  <p>I have added permission in <code>Manifest</code> file:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_CONTACTS"/&gt;
  &lt;uses-permission android:name="android.permission.MODIFY_PHONE_STATE"&gt;&lt;/uses-permission&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"&gt;&lt;/uses-permission&gt;
  &lt;uses-permission android:name="android.permission.CALL_PHONE"&gt;&lt;/uses-permission&gt;
  &lt;uses-feature android:name="android.hardware.telephony" /&gt;
  </code></pre>
  
  <p>Then Create  <code>IDL</code> interface for getting core Telephony service.</p>
  
  <pre><code> package com.android.internal.telephony;
    interface ITelephony {
  
    boolean endCall();
  
    void answerRingingCall();
  
    void silenceRinger();
  }
  </code></pre>
  
  <p>Then made broadcast receiver for incoming call.</p>
  
  <pre><code>public class PhonecallReceiver extends BroadcastReceiver {
  
  Context context = null;
  
  @Override
  public void onReceive(Context context, Intent intent) {
  
        Log.i(TAG, "Receving call...");
        TelephonyManager telephony = (TelephonyManager) 
        context.getSystemService(Context.TELEPHONY_SERVICE);  
        try {
  
             Class c = Class.forName(telephony.getClass().getName());
             Method m = c.getDeclaredMethod("getITelephony");
             m.setAccessible(true);
             ITelephony telephonyService = (ITelephony) m.invoke(telephony);
  
              Bundle b = intent.getExtras();
              String incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
  
              telephonyService.endCall();
  
      }catch (Exception e){  e.printStackTrace(); 
  }}
  </code></pre>