2

I need to automatically reject calls from the list of numbers I have set

I found one solution but it doesn't work

public class IncomingCallReceiver extends BroadcastReceiver {
    private ITelephony telephonyService;
    private String blacklistednumber = "+458664455";
    @Override
    public void onReceive(Context context, Intent intent) {
       TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
       try {
         Class c = Class.forName(tm.getClass().getName());
         Method m = c.getDeclaredMethod("getITelephony");
         m.setAccessible(true);
         ITelephony telephonyService = (ITelephony) m.invoke(tm);
         Bundle bundle = intent.getExtras();
         String phoneNumber = bundle.getString("incoming_number");
         Log.e("INCOMING", phoneNumber);
         if ((phoneNumber != null) && phoneNumber.equals(blacklistednumber)) { 
            telephonyService.silenceRinger();
            telephonyService.endCall();
            Log.e("HANG UP", phoneNumber);
         }
       } catch (Exception e) {
         e.printStackTrace();
       }
}
cutiko
  • 9,887
  • 3
  • 45
  • 59

0 Answers0