Blocking Incomming Calls in Android Smart Phone

We want to blocks all incomming calls in android phone.
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();
  }
}
}

Manifest File


<br /> <manifest android:versioncode="1" android:versionname="1.0" package="com.example.callblockersecond" xmlns:andro></p> <p><uses-sdk android:minsdkversion="8" android:targetsdkversion="15"><br /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"><br /> <uses-permission android:name="android.permission.CALL_PHONE"><br /> <uses-permission android:name="android.permission.READ_PHONE_STATE"><br /> <uses-permission android:name="android.permission.READ_CONTACTS"></p> <p><application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"><br /> <receiver android:name=".Blocker"><br /> <intent-filter android:priority="1000"><br /> <action android:name="android.intent.action.PHONE_STATE"></action><br /> <action android:name="android.intent.action.NEW_OUTGOING_CALL"><br /> </action></intent-filter><br /> </receiver><br /> </application></p> <p></uses-permission></uses-permission></uses-permission></uses-permission></uses-sdk></manifest>

And the following interface with the given package name. Otherwise it would not work .

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.
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.
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.

                                                        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

                                           

Related Posts

Earn Cash on Fiverr: Unlock Your Earning Potential in the Gig Economy

  Have you ever dreamed of turning your skills into cold, hard cash? Well, buckle up, because we’re about to embark on a journey through the exciting…

Become a Freelancer on Guru: How to Land High-Paying Gigs

  Are you ready to take control of your career and dive into the world of freelancing? Look no further than Guru, a platform brimming with opportunities…

how to earn 5 dollar per day from doing micro job

 There are many website which offer micro job . and you can earn 2 or 3 dollar per day from these website when you work few hours…

How to Create blogger website or Blog in Mobile : Complete Tutorial Step by Step

 Blogger blog or website can create easily without any special skills required. Second it’s no need domain and web hosting cost. Therefore creating and develope blogger website…

LinkedIn How to complete 500 connection in one week: Earning Online Unique Method

How You will Complete 500 connection within week. To learn the trick Please watch the video tutorial, then you will easily complete 500 connection within week  1….

How to earn money from used mobile buy sell bussiness

Almost every person of the word are using mobile. many people use 2 or 3 phone at same time. and mostly people change phone after any phone…

This Post Has 3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *