Created
September 19, 2025 02:57
-
-
Save akshat12/365e787ac5ed79470d406914b13b085d to your computer and use it in GitHub Desktop.
MyAccessibilityService.kt - A Working Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MyAccessibilityService.kt | |
| import android.accessibilityservice.AccessibilityService | |
| import android.view.accessibility.AccessibilityEvent | |
| import android.util.Log | |
| class MyAccessibilityService : AccessibilityService() { | |
| private val TAG = "MyAccessibilityService" | |
| override fun onAccessibilityEvent(event: AccessibilityEvent?) { | |
| // We are only listening for window state changes, but it's good practice to check | |
| if (event?.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { | |
| val packageName = event.packageName?.toString() | |
| val className = event.className?.toString() | |
| Log.i(TAG, "Window Changed: \n Package: $packageName\n Class: $className") | |
| } | |
| } | |
| override fun onInterrupt() { | |
| Log.e(TAG, "onInterrupt: Service was interrupted.") | |
| } | |
| override fun onServiceConnected() { | |
| super.onServiceConnected() | |
| Log.d(TAG, "onServiceConnected: Service has been connected.") | |
| // You can set up your service's configuration here if you don't want to use XML | |
| // val info = AccessibilityServiceInfo() | |
| // ... | |
| // serviceInfo = info | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment