I'm trying to block incoming call in android. I have this BroadcastReceiver but it handles the incoming call but does not block incoming call on my android 2.3.6 phone(didn't try on other versions). here is my receiver:
public class PhoneCallReceiver extends BroadcastReceiver {
Context context = null;
private static final String TAG = "Phone call";
private ITelephony telephonyService;
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Receving....");
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.silenceRinger();
telephonyService.endCall();
} catch (Exception e) {
Log.v(TAG, "failed....");
e.printStackTrace();
}
}
}
and the ITelephony
package com.callblocker.mk;
interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}