赞
踩
(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);
}
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。