I can disable the call programmatically for an incoming unknown number in Android 2.2. But in android 4.1 it does not work.
Working code to disconnect a call in Android 2.2:
private Class c; private Method m; private com.android.internal.telephony.ITelephony telephonyService; public void onReceive(Context context, Intent intent) { Bundle b = intent.getExtras(); String state = b.getString(TelephonyManager.EXTRA_STATE); if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) { TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); c = Class.forName(tm.getClass().getName()); m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); telephonyService = (ITelephony) m.invoke(tm); telephonyService.silenceRinger(); telephonyService.endCall(); } }
Please help me. thanks in advance
Finally, I got a solution for version 2.6.
MODIFY_PHONE_STATE permission no longer works on silenceRinger () since version 2.3+, but endCall is just fine. So the solution is to comment on the silentRinger () call.
source share