Yabin Song Yabin Song - 1 year ago 139
Android Question

how to detect accessibility settings on android is enabled/disabled

I'm particularly interested in

high contrast text
color correction
, and
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
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());

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