问题
I am investigating Android AccessibilityService
and wanted to see all possible types of events,
gestures and Key Events.
I am able to receive all public void onAccessibilityEvent(final AccessibilityEvent accessibilityEvent) {}
however my service nevers receives protected boolean onGesture(int gestureId) {}
or
protected boolean onKeyEvent(KeyEvent event) {}
calls.
When I enable my accessibility service in the accessibility settings I see the service connect OK
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?
My Manifest file looks like this
<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>
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" />
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);
}
回答1:
May be you need to change the flag
<?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"
/>
something like this.
or you can also try FLAG_REQUEST_TOUCH_EXPLORATION_MODE
来源:https://stackoverflow.com/questions/43808450/how-to-configure-android-accessibilityservice