Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How do you check if a particular AccessibilityService is enabled

I've written an Android app that requires the use of the AccessibilityService. I know how to check to see if Accessibility is enabled or disabled on the phone, but I cannot work out a way to determine if my app has been specifically enabled within the accessibility menu.

I'm wanting to prompt the user if the AccessibilityService is not running, but can't find a good way of doing this. Is there any API methods that I might be missing that would let me know which accessibility services are enabled on the device?

like image 437
Andrew Avatar asked Feb 22 '11 16:02

Andrew


People also ask

What is an accessibility service?

An Accessibility Service assists users with disabilities in using Android devices and apps. It is a long-running privileged service that helps users process information on the screen and lets them to interact meaningfully with a device.

What is Retrieve window content?

RETRIEVE_WINDOW_CONTENT. retrieve screen content. Allows the app to retrieve the content of the active window. Malicious apps may retrieve the entire window content and examine all its text except passwords.


1 Answers

I worked this one out myself in the end:

public boolean isAccessibilityEnabled() {     int accessibilityEnabled = 0;     final String LIGHTFLOW_ACCESSIBILITY_SERVICE = "com.example.test/com.example.text.ccessibilityService";     boolean accessibilityFound = false;     try {         accessibilityEnabled = Settings.Secure.getInt(this.getContentResolver(),android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);         Log.d(LOGTAG, "ACCESSIBILITY: " + accessibilityEnabled);     } catch (SettingNotFoundException e) {         Log.d(LOGTAG, "Error finding setting, default accessibility to not found: " + e.getMessage());     }      TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');      if (accessibilityEnabled==1) {         Log.d(LOGTAG, "***ACCESSIBILIY IS ENABLED***: ");          String settingValue = Settings.Secure.getString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);         Log.d(LOGTAG, "Setting: " + settingValue);         if (settingValue != null) {              TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;              splitter.setString(settingValue);              while (splitter.hasNext()) {                  String accessabilityService = splitter.next();                  Log.d(LOGTAG, "Setting: " + accessabilityService);                  if (accessabilityService.equalsIgnoreCase(ACCESSIBILITY_SERVICE_NAME)){                      Log.d(LOGTAG, "We've found the correct setting - accessibility is switched on!");                      return true;                  }              }         }          Log.d(LOGTAG, "***END***");     }     else {         Log.d(LOGTAG, "***ACCESSIBILIY IS DISABLED***");     }     return accessibilityFound; } 
like image 73
Andrew Avatar answered Oct 15 '22 01:10

Andrew