Answering a Whatsapp video call programmatically Answering a Whatsapp video call programmatically android android

Answering a Whatsapp video call programmatically


I don't think you can do what you want. Using the AccessibilityService you can know when the video call comes in:

@Overridepublic void onAccessibilityEvent( AccessibilityEvent event ){    if(event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)    {        if(event.getPackageName().equals("com.whatsapp"))        {            StringBuilder sb = new StringBuilder();            List<CharSequence> texts = event.getText();            if (!texts.isEmpty())             {                for (CharSequence s : event.getText())                 {                    sb.append(s);                }                if(sb.toString().equals("Incoming video call"))                {                    Log.d( "onAccessibilityEvent", "whatsapp video call" );                }            }        }    }}

However, I've never been able to answer the call programmatically. The question at How can incoming calls be answered programmatically in Android 5.0 (Lollipop)? does a great job of enumerating all possible options, but most require root and/or being a system app.


You can use sendKeyDownUpSync method from Instrumentation class.

Instrumentation inst = new Instrumentation();inst.sendKeyDownUpSync(KeyEvent.KEYCODE_HEADSETHOOK);

if this code didn't work, try to use another KeyEvent to find the correct one.

You can see the list of KeyEvent from this link : https://developer.android.com/reference/android/view/KeyEvent.html

You can check more info in from here : Instrumentation


A classic way to achieve this is to observe notifications using the NotificationListenerService and act on the relevant action of the notification.