2

In my application I want to block the specific incoming number.I do google,and following Blocking Incoming call - Android. But this code is not working for me.I am testing on android 2.3.5

Here I have no activity class. >> First class is extends BroadcastReceiver.

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blocknumber"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />  
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> 
<uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <receiver android:name=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
    </receiver>
</application>

MainActivity.class

public class MainActivity extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
    String blockedNumbers[] = { "xxxxxxxxxx", "xxxxxxxxxx" };
    Bundle b = intent.getExtras();
    /*
     * String incommingNumber = b
     * .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
     */
    String incommingNumber = b.getString("incoming_number");
    Log.e("Incomming number========>", incommingNumber);
    // String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

    for (int i = 0; i < blockedNumbers.length; i++) {
        Log.e("Incomming >>>>>>>>>>>>>========>", "" + i);
        if (incommingNumber.equalsIgnoreCase(blockedNumbers[i])) {
            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);
                // telephonyService.silenceRinger();
                telephonyService.endCall();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
}

ITelephony

public interface ITelephony {

    boolean endCall();

    void answerRingingCall();

    //void silenceRinger();

}
tshepang
  • 12,111
  • 21
  • 91
  • 136
Rahul Patel
  • 3,823
  • 5
  • 30
  • 46
  • Your rep suggests you've been around SO more than long enough to know that your question is incomplete and that simply asking readers to review your code without knowing what problem they are looking for ("it doesn't work" is not sufficient) is frowned upon strongly. – mah Jun 28 '13 at 11:28

1 Answers1

1

Finally, solve the issue, Create IDL interface for getting core Telephony service package name must be com.android.internal.telephony

FileName : ITelephony.aidl // First Here I am createing ITelephony.java

For the create .aidl file New > File and write ITelephony.aidl

And follow the steps Blocking a call without user intervention in android with an example.

Rahul Patel
  • 3,823
  • 5
  • 30
  • 46