Skip to content

Instantly share code, notes, and snippets.

@akshat12
Created September 19, 2025 02:57
Show Gist options
  • Select an option

  • Save akshat12/365e787ac5ed79470d406914b13b085d to your computer and use it in GitHub Desktop.

Select an option

Save akshat12/365e787ac5ed79470d406914b13b085d to your computer and use it in GitHub Desktop.
MyAccessibilityService.kt - A Working Example
// 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