How can I detect if 'High Contrast' setting (available on Android 5.0+) is enabled in Accessibility settings?
Asked
Active
Viewed 3,751 times
3 Answers
5
In the AccessibilityManager
class (see source here) you have a public method called isHighTextContrastEnabled
that you can use to get your information:
/**
* Returns if the high text contrast in the system is enabled.
* <p>
* <strong>Note:</strong> You need to query this only if you application is
* doing its own rendering and does not rely on the platform rendering pipeline.
* </p>
*
* @return True if high text contrast is enabled, false otherwise.
*
* @hide
*/
public boolean isHighTextContrastEnabled() {
synchronized (mLock) {
IAccessibilityManager service = getServiceLocked();
if (service == null) {
return false;
}
return mIsHighTextContrastEnabled;
}
}
So in your code, you can access this method by doing so (if you're in an Activity
):
AccessibilityManager am = (AccessibilityManager) this.getSystemService(Context.ACCESSIBILITY_SERVICE);
boolean isHighTextContrastEnabled = am.isHighTextContrastEnabled();

alxscms
- 3,067
- 6
- 22
- 43
-
1Not sure why, but isHighTextContrastEnabled() is undefined for AccessibilityManager in my case. – Carrie Feb 19 '16 at 16:20
-
4Just found out that the method is @hide method, so really shouldn't be able to invoke directly like this. Need to invoke it by reflection way. – Carrie May 25 '16 at 19:32
-
This can not help me much more. – Bhaven Shah Jan 04 '21 at 12:51
4
- @alxscms' answer may be right but it does not help me So I found an alternative way to check High contrast text is Enabled or not in android.
Below function will return true if HighContrastText is enabled in user phone and otherwise return false.
Below function is checked in all android phones and it's working.
public static boolean isHighContrastTextEnabled(Context context) {
if (context != null) {
AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
Method m = null;
if (am != null) {
try {
m = am.getClass().getMethod("isHighTextContrastEnabled", null);
} catch (NoSuchMethodException e) {
Log.i("FAIL", "isHighTextContrastEnabled not found in AccessibilityManager");
}
}
Object result;
if (m != null) {
try {
result = m.invoke(am, null);
if (result instanceof Boolean) {
return (Boolean) result;
}
} catch (Exception e) {
Log.i("fail", "isHighTextContrastEnabled invoked with an exception" + e.getMessage());
}
}
}
return false;
}
I hope this can help many more others.

Bhaven Shah
- 692
- 1
- 5
- 18
3
we can check highContrast fonts like this
public boolean isHighTextContrastEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(), "high_text_contrast_enabled", 0) == 1;
}

anuj kumar
- 31
- 1