how to detect accessibility settings on android is enabled/disabled

前端 未结 5 1366
清歌不尽
清歌不尽 2021-01-28 12:34

I\'m particularly interested in high contrast text, color correction, and magnification settings. I did some research online, couldn\'t fi

5条回答
  •  心在旅途
    2021-01-28 13:09

        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

提交回复
热议问题