本文介绍了如何在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
这篇关于如何在Android上检测辅助功能设置已启用/禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!