How to know if Android TalkBack is active?

前端 未结 8 2134
南旧
南旧 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:00

    You can create an inline function in kotlin like:

    fun Context.isScreenReaderOn():Boolean{
        val am = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
        if (am != null && am.isEnabled) {
            val serviceInfoList =
                am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN)
            if (!serviceInfoList.isEmpty())
                return true
        }
        return false}
    

    And then you can just call it whenever you need it like:

    if(context.isScreenReaderOn()){
    ...
    }
    

    Tested and works fine for now.

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

    Open system setting and go to accessibility and tap to off Talk back option

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

    Novoda have released a library called accessibilitools which does this check. It queries the accessibility manager to check if there are any accessibility services enabled that support the "spoken feedback" flag.

    AccessibilityServices services = AccessibilityServices.newInstance(context);
    services.isSpokenFeedbackEnabled();
    
    0 讨论(0)
  • 2020-12-02 16:09
        AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (am != null && am.isEnabled()) {
            List<AccessibilityServiceInfo> serviceInfoList = am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN);
            if (!serviceInfoList.isEmpty())
                return true;
        }
        return false;
    
    0 讨论(0)
  • 2020-12-02 16:10

    For me, I solved this problem in this way , it works well in my project:

    1. use getEnabledAccessibilityServiceList() to get all Accessibility service, a service whose status is open will be in this list
    2. Talkback contain a activity named com.android.talkback.TalkBackPreferencesActivity, you can traversing the list to find whether the talkback service is open

    The detailed code below:

        private static final String TALKBACK_SETTING_ACTIVITY_NAME = "com.android.talkback.TalkBackPreferencesActivity";
    
        public static boolean accessibilityEnable(Context context) {
            boolean enable = false;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                try {
                    AccessibilityManager manager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
                    List<AccessibilityServiceInfo> serviceList = manager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN);
                    for (AccessibilityServiceInfo serviceInfo : serviceList) {
                        String name = serviceInfo.getSettingsActivityName();
                        if (!TextUtils.isEmpty(name) && name.equals(TALKBACK_SETTING_ACTIVITY_NAME)) {
                            enable = true;
                        }
                    }
                } catch (Exception e) {
                    if (Logging.isDebugLogging()) {
                        e.printStackTrace();
                    }
                }
            }
            return enable;
    }
    
    0 讨论(0)
  • 2020-12-02 16:12

    For an example, look at isScreenReaderActive() in HomeLauncher.java file in the Eyes-Free shell application (via groups thread).

    To sum up: you detect all screen readers with Intents, then query the status provider of each to see if it is active.

    If you really want to limit it to TalkBack only, you could try checking the ResolveInfo.serviceInfo.packageName for each result returned from queryIntentServices() to see if it matches the TalkBack package.

    0 讨论(0)
提交回复
热议问题