Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if my accessibility service is enabled

I was wondering how could I detect if my own service is enabled. So I could check if my service is not enabled, then tell the user to enable it.

like image 700
Rotary Heart Avatar asked Aug 07 '13 04:08

Rotary Heart


People also ask

How do I turn on Accessibility services?

To access the Accessibility features on your Android device open the Settings app . In the Settings app, select Accessibility from the list. On the Accessibility screen, scroll down to the Interaction controls section and select Accessibility Menu. On the next screen, set the toggle switch for Accessibility Menu to On.

How do I turn off Accessibility services?

Open your Android device's Settings app . Select Accessibility. Switch Access. At the top, select the On/Off switch.

What is an Accessibility service on my phone?

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.


1 Answers

Below is the method to check if your accessibility service is enabled or not. 

Note: Change value of YOURAccessibilityService with your Service. 

// To check if service is enabled private boolean isAccessibilitySettingsOn(Context mContext) {     int accessibilityEnabled = 0;     final String service = getPackageName() + "/" + YOURAccessibilityService.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; } 

And to call this method:

if (!isAccessibilitySettingsOn(getApplicationContext())) {     startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)); } 

This will check and launch accessibility settings if not enabled.

like image 193
Pankaj Kumar Avatar answered Sep 29 '22 21:09

Pankaj Kumar