1

I am trying to develop a basic code to block calls in Android. My code was working initially but now it is not.

code to block all calls

    @Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    try {
        Class<?> c = Class.forName(tm.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);

ITelephony is the interface used

        telephony = (ITelephony) m.invoke(tm);

cannot call any of the available functions

        telephony.endCall();
        telephony.notifyAll();
    } catch (Exception e) {
        // TODO: handle exception
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

When you do this:

m.setAccessible(true);

you effectively are trying to bypass Java security. On some devices with old Android version it may have worked, but on more locked down devices it is not guaranteed to.

mvp
  • 111,019
  • 13
  • 122
  • 148