This might be useful. Try this,
Add this in AndroidManifest.xml
<service
android:name="com.example.Accessibility"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service" />
</service>
accessibility_service.xml in xml folder
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeViewFocused|typeViewTextChanged|typeViewClicked|typeWindowStateChanged|typeWindowContentChanged|typeWindowsChanged"
android:accessibilityFeedbackType="feedbackGeneric|feedbackVisual"
android:canRetrieveWindowContent="true"
android:accessibilityFlags="flagReportViewIds|flagIncludeNotImportantViews"
android:description="@string/app_name"
android:canPerformGestures="true"
android:notificationTimeout="150">
</accessibility-service>