Incoming call blocking code is not working in real device
<p>I have use the following code for incoming call blocking
<a href="http://stackoverflow.com/questions/3809588/how-to-reject-incoming-">How to reject incoming call programatically in android?</a><br>
call-programatically-in-android</p>

<p>It completely works in emulator but not on real device please give mw some solution 
Is that any permission required from google.
and telephonyService.endCall() also not working.</p>

<pre><code>package com.android.MyCellFamily.DAReceiver;
import java.lang.reflect.Method;
import com.android.MyCellFamily.DAService.LocationService;
import com.android.MyCellFamily.DB.ClsDataBaseUtils;
import com.android.internal.telephony.ITelephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class ClsIncomingCallBlocker_DAReceiver extends BroadcastReceiver {
    ClsDataBaseUtils dts=new ClsDataBaseUtils();
    String clsincommingNumber;

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        try
        {

            dts.createDatabse("MyCellFamily",context);
            dts.createTable("tbl_Contacts", context); 
            dts.createBlockedStatusTable("tbl_BlockedContacts", context);

            MyPhoneStateListener myPhoneStateListener = new MyPhoneStateListener();
            ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).listen(myPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            Class c = Class.forName(tm.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            com.android.internal.telephony.ITelephony telephonyService =(ITelephony)m.invoke(tm);


            Bundle b = intent.getExtras();
            clsincommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Log.d("clsincommingNumber",clsincommingNumber);
            if(dts.checkPreffContactsFrInCall("tbl_Contacts", clsincommingNumber).equals("true"))
            {
            //Answer Ringing Call
            telephonyService.answerRingingCall();
            dts.close();    
            }   
            else if(dts.checkBlockedStatusFrInCall("tbl_BlockedContacts", clsincommingNumber).equals("true"))
            {
            System.out.println("Incoming blocker"+dts.checkBlockedStatusFrInCall("tbl_BlockedContacts", clsincommingNumber));
            //block incoming call
            telephonyService.endCall();
            dts.close();
            }
            else if(LocationService.getStatusOfDriving().equals("block"))
            {
            System.out.println("Your Status Of Driving is"+LocationService.getStatusOfDriving().toString());
            telephonyService.endCall();
            this.setResultData(null);
            }   
            else
            {
            //Answer Ringing Call
            telephonyService.answerRingingCall();
            dts.close();
            }   

        }
        catch(Exception e)
        {

        }
    }
}
</code></pre>
