0

I am using this code:

        try {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            Class<?> c = Class.forName(tm.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
            telephonyService = (ITelephony) m.invoke(tm);

            // telephonyService.silenceRinger();
            telephonyService.answerRingingCall();
        } catch (Exception e) {
            e.printStackTrace();
        }

This code needs Modify_Phone_State permission which is depreciated. Any alternative way to auto answer the incoming calls?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Android Dev
  • 5
  • 1
  • 5

1 Answers1

0

This is not allowed by default as the MODIFY_PHONE_STATE permissions is not for 3rd party applications.

However, you can use reflection to invoke telephony APIs that are not exposed, but this can lead to unexpected behaviours as these APIs are subject to change with each Android release.

Check this answer here:How can incoming calls be answered programmatically in Android 5.0 (Lollipop)?

Community
  • 1
  • 1
Mina Wissa
  • 10,923
  • 13
  • 90
  • 158