gpt4 book ai didi

android - 如何配置 Android AccessibilityService

转载 作者:行者123 更新时间:2023-11-29 01:10:01 30 4
gpt4 key购买 nike

我正在调查 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 accessibilityservice 内容是:-

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

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com