Last active
August 29, 2015 14:09
-
-
Save danielgomezrico/bfc7ca1cd59e9bcd035a to your computer and use it in GitHub Desktop.
Know if the Accessibility Service is enabled in settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if Accessibility service is enabled | |
* | |
* @param context | |
* @return | |
*/ | |
private boolean isAccessibilitySettingsOn(Context context) { | |
int accessibilityEnabled = 0; | |
final String service = "<apppackage>/<servicepackage>"; | |
boolean accessibilityFound = false; | |
try { | |
accessibilityEnabled = Settings.Secure.getInt( | |
context.getApplicationContext().getContentResolver(), | |
android.provider.Settings.Secure.ACCESSIBILITY_ENABLED); | |
Timber.v("accessibilityEnabled = " + accessibilityEnabled); | |
} catch (Settings.SettingNotFoundException e) { | |
Timber.e("Error finding setting, default accessibility to not found: " | |
+ e.getMessage()); | |
} | |
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':'); | |
if (accessibilityEnabled == 1) { | |
Timber.v("***ACCESSIBILIY IS ENABLED*** -----------------"); | |
String settingValue = Settings.Secure.getString( | |
context.getApplicationContext().getContentResolver(), | |
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); | |
if (settingValue != null) { | |
TextUtils.SimpleStringSplitter splitter = mStringColonSplitter; | |
splitter.setString(settingValue); | |
while (splitter.hasNext()) { | |
String accessabilityService = splitter.next(); | |
Timber.v("-------------- > accessabilityService :: " + accessabilityService); | |
if (accessabilityService.equalsIgnoreCase(service)) { | |
Timber.v("We've found the correct setting - accessibility is switched on!"); | |
return true; | |
} | |
} | |
} | |
} else { | |
Timber.v("***ACCESSIBILIY IS DISABLED***"); | |
} | |
return accessibilityFound; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment