How to detect when user turns on/off talkback in android programmatically

31

January 12, 2019, at 10:30 PM

I'm trying to update the UI based on accessibility option (i.e. talkback on/off). When user turns on talkback, i need to show some helper text else the helper text should be hidden.

As we also have shortcuts (In Pixel device, long pressing on both up and down volume keys) to enable/disable talkback. Is there any way to detect whether talkback is enabled/disabled, when i am on XYZ activity.

Answer 1

You can use AccessibilityManager.AccessibilityStateChangeListener to receive whether listen to changes in Accessibilty Service.

Unfortunately this will be true if ANY of the accessibilty services are enabled.

You can also try using getEnabledAccessibilityServiceList. This will return the list of all active accessibility services. But this will not be a listener meaning you'll not get a callback if this changes. A hack would be to call this function at regular intervals to check if anything has changed.