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.

AccessibilityManager accessibiltyManager= (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
// Put this in onCreate
accessibiltyManager.addAccessibilityStateChangeListener(new AccessibilityManager.AccessibilityStateChangeListener() {
    @Override
    public void onAccessibilityStateChanged(boolean b) {
        accessibiltyChanged(b);
    }
});
accessibiltyChanged(accessibiltyManager.isEnabled());
void accessibiltyChanged (Boolean enabled) {
   // Do your stuff
}

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.

READ ALSO
Moving to previous fragment from activity

Moving to previous fragment from activity

I have three fragments in the appI am creating, call them f1,f2, f3

68
How to hook photo call api on android?

How to hook photo call api on android?

I have an APK which taking photos once Button "Take Photo " clickedAPP pop-up photo api and taking picture

52
Scroll Recycleview to Top position when activity starts using Linearlayoutmanager

Scroll Recycleview to Top position when activity starts using Linearlayoutmanager

I"m retrieving Firebase RealTime Database to my Recycleview Adapter ClassI want to sort the data by date with latest post at top

40
Is there a way to visualize how a fragment would look like when it's loaded in adnroid studio inspector?

Is there a way to visualize how a fragment would look like when it's loaded in adnroid studio inspector?

I'm making an android app that has a couple of fragments in itI was wondering if you could look at how your fragments would look like when they are loaded in the layout inspector

57