androidaccessibilityservice

(Android) How to detect the press of the virtual back button, home button and overview button


I wondered how to detect the press of Android's virtual back button, home button, and overview button. For "virtual", I mean the 3-button navigation on Android, which can be illustrated by the blue area in the screenshot. I used onKeyEvent method at my AccessibilityService and this method can successfully detect the press of all the buttons in the read area of the screenshot. However, it failed to detect the press of the buttons in the blue area. Is there any way we can also detect the press of buttons in the blue area?

Physical Buttons and Virtual Buttons

1


Solution

  • Yeah the viewResourceId of these buttons are :

    So in your onAccessibilityEvent you might do the following

    @Override
    public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        if (accessibilityEvent.getSource() != null){
            if (accessibilityEvent.getSource().getViewIdResourceName().equals("any of the values given above as home...."){
                //Do your stuff
            }
        }