我正在调查 AndroidAccessibilityService
并希望查看所有可能类型的事件、手势和关键事件。
我能够收到所有public void onAccessibilityEvent(final AccessibilityEvent accessibilityEvent) {}
但是我的服务从不接听protected boolean onGesture(int gestureId) {}
或
protected boolean onKeyEvent(KeyEvent event) {}
打电话。
当我在辅助功能设置中启用辅助功能服务时,我看到服务连接正常
public void onAccessibilityEvent(final AccessibilityEvent accessibilityEvent) {}
我可以看到服务从方法中注销
我没有配置什么?还是配置不正确?
我的清单文件看起来像这样
<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 无障碍服务内容是:-
<?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 如下:-
@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);
}