How to answer incoming call programmatically in Android

Published by Igor Khrupin on

Here is example for accepting incoming calls programmatically

The most stable version is using adb shell feature.

Call can be answered by sending command “adb shell input keyevent 79” via Terminal

Same thing can be done programmatically.

But, it works good for user-driven answering and this solution good for custom call screen.
It will not work for any sort of automated call-control-type applications.
Like auto answering via BroadcastReceivers etc.

Screenshot 2016-05-26 13.54.20

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

Awaiting comments. Let me know the better ways.


3 Comments

srijana karkidholi · 16 September, 2016 at 07:09

awesome

Peter · 13 January, 2017 at 15:03

This method is unfortunately dead in android 7.0. I have also one moto g 3. edition where it does not work on android 6.0 🙁 Any other ideas how to do this?

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.