Create new project and extand it main class from BroadCast Receiver.
private ITelephony telephonyService;
private String incommingNumber;
private String incommingName=null;
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
Bundle b = intent.getExtras();
String state = b.getString(TelephonyManager.EXTRA_STATE);
if ((state != null)&& (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)))
{
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
try
{
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();
}
}
}
Manifest File
And the following interface with the given package name. Otherwise it would not work .
public interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
Let enjoy. it will block all your incomming call in android phone.
If you want to block all unsaved numbers than add the following method.
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String name=null;
ContentResolver contentResolver =c.getContentResolver();
Cursor contactLookup = contentResolver.query(uri, new String[] {BaseColumns._ID,
ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);
try {
if (contactLookup != null && contactLookup.getCount() > 0) {
contactLookup.moveToNext();
data = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
//String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID));
}
} finally {
if (contactLookup != null) {
contactLookup.close();
}
}
return name;
}
In this method we search the calling number in contacts . If it is available than ignor blocking else block it.
Now Add the following number of line to the onReceive( ) method
String state = b.getString(TelephonyManager.EXTRA_STATE);
if ((state != null)&& (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)))
{
incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
incommingName=getContactDisplayNameByNumber(incommingNumber, context);
if((incommingName==null)||(incommingName.length()<=1))
{ TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try
{
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();
}
}
}
It block only unsaved numbers.You also block any particular or list of numbers.
Now I Write Call Blocker Application for android where you can block All, unsaved and customized list number form calling to you. All classes, source code, screen shot and Apk are download load from the below link. BlockCall Download Here
Screen Shot of Call Blocker App
Hi sir i need code for call blocker please send me. chandbecse@gmail.com
Dear !
Source Code is given at the end of tutorial.Please download it.
Files for the source code is missing!!