Skip to content

Instantly share code, notes, and snippets.

@miguelhincapie
Created April 4, 2020 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelhincapie/d5ab4ceefb4bad9ae3f0cf01e9d22ce1 to your computer and use it in GitHub Desktop.
Save miguelhincapie/d5ab4ceefb4bad9ae3f0cf01e9d22ce1 to your computer and use it in GitHub Desktop.
Generic way to listen for any change in accessibility services state
/**
* Observe for any accessibility service state change. Use [AccessibilityManager] to list
* current accessibility service ON or send [AccessibilityEvent] like a speech out.
*/
private fun listenForAccessibilityServiceStatus(context: Context) {
val accessibilityManager =
context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
accessibilityManager.addAccessibilityStateChangeListener { enabled ->
// Do your stuff
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment