Search code examples
androidaccessibilityserviceaccessibility

Capturing all events from accessibility service


I have implemented an accessibility service for Android 7.0. The code is shown below. I would like to catch all possible events and just print them to console. The problem now is that when I start the service I'm receiving the events but the phone does not react to touch input anymore, i.e. the phone is basically blocked.

What is my mistake? Is capturing all events a problem in terms of performance or CPU load? Most of the time skype will be used (chatting) and sometimes Chrome browser.

Manifest

<service android:name=".smartphone.MyAccessibilityService"
    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_config" />
</service>

accessibility_config.xml

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackAllMask"
    android:canRequestTouchExplorationMode="true"
    android:canRequestEnhancedWebAccessibility="true"
    android:canRequestFilterKeyEvents="true"
    android:canRetrieveWindowContent="true"
    android:accessibilityFlags="flagDefault|flagIncludeNotImportantViews|flagReportViewIds|flagRequestEnhancedWebAccessibility|flagRequestFilterKeyEvents|flagRequestTouchExplorationMode|flagRetrieveInteractiveWindows" />

MyAccessibilityService.java

public class MyAccessibilityService extends AccessibilityService {
    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        Log.i("ACCESSIBILITY SERVICE", "ACCESSIBILITY SERVICE : " + event.toString());
    }

Solution

  • flagRequestTouchExplorationMode has turned on touch exploration mode, which is what's affecting how your device reacts to touches.