android – onAccessibilityEvent根本没有被调用
作者:互联网
我正在尝试实现AccessibilityService.我在下面分享了我的代码.
当我从设置菜单打开辅助功能服务时,会调用onServiceConnected(),但根本不会调用onAccessibiltyEvent().请指导我这个.
清单文件中的服务声明.
<service
android:name=".MyAccessibilityService"
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/accessibility_service_config" />
</service>
XML文件
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/accessibility_service_description"
android:accessibilityEventTypes="typeAllMask"
android:canRequestFilterKeyEvents="true"
android:accessibilityFlags="flagDefault"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
/>
MyAccessibiltyService.java
public class MyAccessibilityService extends AccessibilityService {
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Log.d(TAG,"Service Connected");
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
System.out.println("Event Occurred");
Log.d(TAG, "onAccessibilityEvent: event=" + event);
AccessibilityNodeInfo nodeInfo = event.getSource();
if (null == nodeInfo) return;
}
@Override
public void onInterrupt() {
Log.d(TAG,"Accessibility Interrupted" );
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG,"Service Destroyed");
}
}
请注意,我已经检查了所有stackoverflow答案,因此不要将其标记为重复.
解决方法:
我需要在accessibility_service_config文件中添加反馈类型以使其工作.
尝试添加此功能
android:accessibilityFeedbackType="feedbackAllMask"
使用Android 7.1.2在Nexus 6P上进行测试
标签:android,accessibility,accessibilityservice,accessibility-api,android-accessibili 来源: https://codeday.me/bug/20190611/1218599.html