Yabin Song Yabin Song - 6 months ago 54
Android Question

how to detect accessibility settings on android is enabled/disabled

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();


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.

Answer
    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;
    }

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

Comments