I want to block all incoming calls but get notified. For this I'm implementing this code:
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(tm);
Bundle bundle = intent.getExtras();
String phoneNumber = bundle.getString("incoming_number");
Log.d("INCOMING", phoneNumber);
if ((phoneNumber != null)) {
telephonyService.endCall();
Log.d("HANG UP", phoneNumber);
}
} catch (Exception e) {
e.printStackTrace();
}
But sometimes it does not work perfectly, I mean sometimes it does not response instantly, so the phone starts ringing for a very short time and then "telephonyService.endCall()" ends the call. I want to block the call instantly without providing time for ringing. Is it possible?