AccessibilityService没有响应OnKeyEvent()

时间:2015-06-24 17:41:40

标签: java android service automation accessibility

您好我正在构建辅助功能服务。我想处理键盘输入,并确定swagger: '2.0' # This is your document metadata info: version: "0.0.1" title: Todo App schema: { } host: localhost:3000 schemes: - http - https consumes: - application/json produces: - application/x-www-form-urlencoded basePath: / paths: # This is a path endpoint. Change it. /tasks: post: description: | Add 'Task' object. parameters: # An example parameter that is in query and is required - name: name in: query description: unique object task name required: true schema: type: string - name: description in: query description: task description required: true schema: type: string responses: # Response code 200: description: Successful response # A schema describing your response object. # Use JSON Schema format schema: title: Return String type: string example: "Task added succesfully" 500: description: Error schema: type: string example: "Could not add Task" 键事件。我想我的最佳镜头是覆盖BACK回调。但我发现它甚至从未被召唤过。我试图添加onKeyEvent()"在配置XML中以及我添加的android:canRequestFilterKeyEvents="true模块中

onServiceConnected

但仍然没有运气。看起来偶数info.flags=AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS; info.flags=AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS; setServiceInfo(info); 永远不会被提出。

1 个答案:

答案 0 :(得分:1)

如果你想处理homebutton和back按钮的事件,你必须添加:

在声明的xml服务中:

1-android:canRequestFilterKeyEvents="true"
2-Add flagRequestFilterKeyEvents to your android:accessibilityFlags

在辅助功能服务类中添加onKeyEvent:

  @Override
        public boolean onKeyEvent(KeyEvent event) {
            int keyCode = event.getKeyCode();

            switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    Log.e(TAG, "Back");

                case KeyEvent.KEYCODE_HOME:
                    Log.e(TAG, "Home");
                    return false;
            }
            return super.onKeyEvent(event);
        }