How to know if Android TalkBack is active?

前端 未结 8 2135
南旧
南旧 2020-12-02 15:23

I\'m developing an application that uses TalkBack to guide people through it. However, in those situations I want to have some subtile differences in the layout of the appli

相关标签:
8条回答
  • 2020-12-02 16:16

    Thanks to @david-z answer (https://stackoverflow.com/a/41357058/2713403) I made this approach to know if the Android Accessibility Suite by Google is enabled

    /**
     * This method checks if Google Talkback is enabled by using the [accessibilityManager]
     */
    private fun isGoogleTalkbackActive(accessibilityManager : AccessibilityManager) : Boolean
    {
        val accessibilityServiceInfoList = accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN)
        for (accessibilityServiceInfo in accessibilityServiceInfoList)
        {
            if ("com.google.android.marvin.talkback".equals(accessibilityServiceInfo.resolveInfo.serviceInfo.processName))
            {
                return true
            }
        }
        return false
    }
    

    Remember to register the google URI as constant :) and get the Accessibility Manager instance as @caseyburkhardt says (https://stackoverflow.com/a/12362545/2713403). The difference with the @david-z answer is that I got the Android Accessibility Suite package name instead of its app name because it is more secure. If you want to review if another accessibility suite is enabled (like the Samsung Screen Reader) after this check, you can check if (accessibilityManager.isTouchExplorationEnabled)

    Cheers!

    0 讨论(0)
  • 2020-12-02 16:18

    The recommended way of doing this is to query the AccessibilityManager for the enabled state of accessibility services.

    AccessibilityManager am = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
    boolean isAccessibilityEnabled = am.isEnabled();
    boolean isExploreByTouchEnabled = am.isTouchExplorationEnabled();
    
    0 讨论(0)
提交回复
热议问题