Search code examples
javaandroidandroid-studioaccessibilitytalkback

How to check TalkBack on/off status and get change notifications in Android mobile?


I'm working on an Android mobile application and need to know if TalkBack is active on startup and detect TalkBack off/on state changes while application is running.

Previously the code used JavaScript accessibility component and called C++ and then Java. Now we only want Java code.

How can I implement this functionality?


Solution

  • I was able to get the Talkback active/inactive status notification using AccessibilityManager.addTouchExplorationStateChangeListener. This resolved the issue I had with Android mobile.

        try {
            am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    
            am.addTouchExplorationStateChangeListener(new AccessibilityManager.TouchExplorationStateChangeListener () {
                @Override
                public void onTouchExplorationStateChanged(boolean enabled) {
                    onTalkbackStatusChanged(enabled);
                }
            });
        } catch(Exception ex) {
           ...
        }