Adding an accessibility service in android


Add the following in the AndroidManifest.xml:


android:name=".MyAccessibilityService"    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"    android:label="@string/accessibilityServiceName">    
        android:name="android.accessibilityservice.AccessibilityService"/>    

android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice"/>

Create the file res/xml/accessibilityservice.xml:


xml version="1.0" encoding="utf-8"?>    xmlns:tools="http://schemas.android.com/tools"    android:accessibilityEventTypes="typeWindowStateChanged"    android:accessibilityFeedbackType="feedbackGeneric"    android:accessibilityFlags="flagIncludeNotImportantViews"    android:description="@string/accessibility_service_description"    xmlns:android="http://schemas.android.com/apk/res/android"    tools:ignore="UnusedAttribute"/>


Create MyAccessibilityService.java with:

package com.mypackage;
import android.accessibilityservice.AccessibilityService;
import android.view.accessibility.AccessibilityEvent;
public class MyAccessibilityService extends AccessibilityService {

    @Override    public void onAccessibilityEvent(AccessibilityEvent event) {
        
    }

    @Override    public void onInterrupt() {

    }
}

Comments