问题描述
我正在调查Android AccessibilityService
,并希望查看所有可能的事件类型,
手势和按键事件。
I am investigating Android AccessibilityService
and wanted to see all possible types of events,gestures and Key Events.
我能够接收所有无效的onAccessibilityEvent(final AccessibilityEvent accessibilityEvent){}
我的服务永远不会收到受保护的布尔onGesture(int poseId){}
或
受保护的布尔onKeyEvent(KeyEvent event){}
呼叫。
however my service nevers receives protected boolean onGesture(int gestureId) {}
orprotected boolean onKeyEvent(KeyEvent event) {}
calls.
在辅助功能设置中启用我的辅助功能后,我看到该服务已连接
When I enable my accessibility service in the accessibility settings I see the service connect OK
然后我看到服务从公共无效ononAccessibilityEvent(final AccessibilityEvent accessibilityEvent){}
方法注销
and I can see the service logging out from the public void onAccessibilityEvent(final AccessibilityEvent accessibilityEvent) {}
method
我没有配置什么?还是配置错误?
What have I not configured? or configured incorrectly?
我的清单文件是这样的
<service
android:name=".MyAccessibilityService"
android:label="My Accessibility"
android:enabled="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibilityservice" />
</service>
xml可访问性服务的内容为:-
The xml accessibilityservice contents are :-
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackSpoken"
android:accessibilityFlags="flagDefault"
android:canRequestEnhancedWebAccessibility="true"
android:canRequestFilterKeyEvents="true"
android:canRequestTouchExplorationMode="true"
android:canRetrieveWindowContent="true"
android:notificationTimeout="1000"
android:packageNames="com.research.my.accessibility" />
服务AccessibilityServiceInfo如下:-
The service AccessibilityServiceInfo is as follows:-
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Log.d("TAG", "onServiceConnected");
final AccessibilityServiceInfo accessibilityServiceInfo = new AccessibilityServiceInfo();
accessibilityServiceInfo.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
accessibilityServiceInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
accessibilityServiceInfo.packageNames = new String[] {"com.research.my.accessibility"};
accessibilityServiceInfo.notificationTimeout = 1000;
setServiceInfo(accessibilityServiceInfo);
}
推荐答案
可能是您需要更改标记
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeContextClicked|typeViewClicked"
android:packageNames="com.example.andres.eventcapture"
android:accessibilityFlags="flagRequestFilterKeyEvents"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="50"
android:canRetrieveWindowContent="true"
android:settingsActivity=""
android:canRequestFilterKeyEvents="true"
/>
类似这样的东西。
也可以尝试FLAG_REQUEST_TOUCH_EXPLORATION_MODE
or you can also try FLAG_REQUEST_TOUCH_EXPLORATION_MODE
这篇关于如何配置Android AccessibilityService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!