如何在Android上检测辅助功能设置已启用/禁用

如何在Android上检测辅助功能设置已启用/禁用

问题描述:

我对高对比度文本色彩校正放大率设置特别感兴趣.我在网上做了一些研究,找不到我想要的东西.我看到了一个有关检测高对比度文本的答案:

I'm particularly interested in high contrast text, color correction, and magnification settings. I did some research online, couldn't find what I want. I saw one answer about detecting high contrast text:

AccessibilityManager am = (AccessibilityManager) this.getSystemService(Context.ACCESSIBILITY_SERVICE);
boolean isHighTextContrastEnabled = am.isHighTextContrastEnabled();

但是不知何故,它给我 isHighTextContrastEnabled()错误,说它对于AccessibilityManager类型是未定义的.

But somehow it gives me the error for isHighTextContrastEnabled() saying that it is undefined for the type AccessibilityManager.

也没有找到其他两个设置检测的解决方案.

Also didn't find solution for the other two settings detection.

    AccessibilityManager am = (AccessibilityManager) this.getSystemService(Context.ACCESSIBILITY_SERVICE);

    Class clazz = am.getClass();
    Method m = null;
    try {
        m = clazz.getMethod("isHighTextContrastEnabled",null);
    } catch (NoSuchMethodException e) {
        Log.w("FAIL", "isHighTextContrastEnabled not found in AccessibilityManager");
    }


    Object result = null;
    try {
        result = m.invoke(am, null);
        if (result != null && result instanceof Boolean)  {
            Boolean b = (Boolean)result;
            Log.d("result", "b =" + b);
        }
    }  catch (Exception e) {
        android.util.Log.d("fail",  "isHighTextContrastEnabled invoked with an exception" + e.getMessage());
        return;
    }

我进行测试,它返回false,因此可以正常工作

and I do test, it return false, so it works