How in the application (dialer) can I automatically answer incoming calls? I find everywhere only the call indication methods.

Below is the code that can automatically reset ( endCall() ), but for some reason the answerRingingCall() function does not want to work.

 try { TelephonyManager manager = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); Class c = Class.forName(manager.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephony = (ITelephony)m.invoke(manager); telephony.endCall(); } catch(Exception e){ Log.d("",e.getMessage()); } 
  • As far as I understand, for answerRingingCall() , the answerRingingCall() must be declared: android.permission.MODIFY_PHONE_STATE - Barmaley
  • This is, of course, done - sqlbastard1613
  • in general, I have already found information that since android 2.3.3 this method is no longer relevant because the question is still open - sqlbastard1613

1 answer 1

The solution was found:

 try { Runtime.getRuntime().exec("input keyevent " + Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK)); } catch (IOException e) { } 

https://stackoverflow.com/questions/26924618/how-can-incoming-calls-be-answered-programmatically-in-android-5-0-lollipop