简体   繁体   English

(Android) 如何检测虚拟后退按钮、主页按钮和概览按钮的按下

[英](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.我想知道如何检测 Android 的虚拟后退按钮、主页按钮和概览按钮的按下。 For "virtual", I mean the 3-button navigation on Android, which can be illustrated by the blue area in the screenshot.对于“虚拟”,我指的是 Android 上的3 键导航,可以通过屏幕截图中的蓝色区域进行说明。 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.我在 AccessibilityService 中使用了 onKeyEvent 方法,该方法可以成功检测到屏幕截图读取区域中所有按钮的按下情况。 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

Yeah the viewResourceId of these buttons are:是的,这些按钮的viewResourceId是:

  • Home: com.android.systemui:id/home_button主页: com.android.systemui:id/home_button
  • Back: com.android.systemui:id/back返回: com.android.systemui:id/back
  • Recent Apps: com.android.systemui:id/recent_apps最近的应用程序: com.android.systemui:id/recent_apps

So in your onAccessibilityEvent you might do the following因此,在您的 onAccessibilityEvent 中,您可能会执行以下操作

@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
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM