我正在调查 Android AccessibilityService 并想查看所有可能的事件类型,
手势和关键事件。

我能够收到所有 public void onAccessibilityEvent(final AccessibilityEvent accessibilityEvent) {}
但是我的服务从未收到 protected boolean onGesture(int gestureId) {}protected boolean onKeyEvent(KeyEvent event) {} 调用。

当我在辅助功能设置中启用我的辅助功能服务时,我看到服务连接正常

我可以看到服务从 public void onAccessibilityEvent(final AccessibilityEvent accessibilityEvent) {} 方法中注销

我没有配置什么?或配置不正确?

我的 list 文件看起来像这样

<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);
}

最佳答案

可能是您需要更改标志

<?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

关于android - 如何配置 Android AccessibilityService,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43808450/

10-12 05:21