Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onAccessibilityEvent not called at all

I am trying to implement an AccessibilityService. I have shared my code below. When I turn on my accessibility service from settings menu then onServiceConnected() is called but onAccessibiltyEvent() is not called at all. Please guide me on this.

Service Declaration in manifest file.

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

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

Please note that I have already checked all stackoverflow answers hence do not mark this as duplicate.

like image 902
vipin agrahari Avatar asked Nov 09 '16 09:11

vipin agrahari


1 Answers

I needed to add a feedback type to the accessibility_service_config file to make it work.

Try to add this

android:accessibilityFeedbackType="feedbackAllMask"

Tested on a Nexus 6P with Android 7.1.2

like image 69
Asapha Avatar answered Sep 19 '22 17:09

Asapha