当前位置:   article > 正文

Android 判断无障碍服务权限是否已经打开

Android 判断无障碍服务权限是否已经打开

(Android无障碍服务开发QQ群:752296312) 
本文以下内容转摘自:https://blog.csdn.net/liuhongshuo2012/article/details/50751076
1、判断无障碍服务是否已经打开的方法:
private boolean isAccessibilitySettingsOn(Context mContext) {
int accessibilityEnabled = 0;
final String service = getPackageName() + "/" + AutoFire.class.getCanonicalName();
try {
accessibilityEnabled = Settings.Secure.getInt(
mContext.getApplicationContext().getContentResolver(),
android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
// Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
} catch (Settings.SettingNotFoundException e) {
// Log.e(TAG, "Error finding setting, default accessibility to not found: "
// + e.getMessage());
}
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

if (accessibilityEnabled == 1) {
// Log.v(TAG, "***ACCESSIBILITY IS ENABLED*** -----------------");
String settingValue = Settings.Secure.getString(
mContext.getApplicationContext().getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
if (settingValue != null) {
mStringColonSplitter.setString(settingValue);
while (mStringColonSplitter.hasNext()) {
String accessibilityService = mStringColonSplitter.next();

// Log.v(TAG, "-------------- > accessibilityService :: " + accessibilityService + " " + service);
if (accessibilityService.equalsIgnoreCase(service)) {
// Log.v(TAG, "We've found the correct setting - accessibility is switched on!");
return true;
}
}
}
} else {
// Log.v(TAG, "***ACCESSIBILITY IS DISABLED***");
}

return false;
}

2、然后在onCreate()方法中:
//判断无障碍服务是否已经打开,没打开则进入无障碍设置界面
if(!isAccessibilitySettingsOn(this)) {
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
this.startActivity(intent);
}
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/310956
推荐阅读
相关标签
  

闽ICP备14008679号