We want to blocks all incomming calls in android phone.
Create new project and extand it main class from BroadCast Receiver.
Manifest File
And the following interface with the given package name. Otherwise it would not work .
If you want to block all unsaved numbers than add the following method.
Now Add the following number of line to the onReceive( ) method
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
Create new project and extand it main class from BroadCast Receiver.
public class Blocker extends BroadcastReceiver {
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();
}
}
}
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
package com.android.internal.telephony;
public interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
Let enjoy. it will block all your incomming call in android phone. public interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
If you want to block all unsaved numbers than add the following method.
public String getContactDisplayNameByNumber(String number, Context c) {
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.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;
}
Now Add the following number of line to the onReceive( ) method
Bundle b = intent.getExtras();
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.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();
}
}
}
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
3 Comments
Hi sir i need code for call blocker please send me. chandbecse@gmail.com
ReplyDeleteDear !
DeleteSource Code is given at the end of tutorial.Please download it.
Files for the source code is missing!!
Delete