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.

Thanks

  • Android - Set TalkBack accessibility focus to a specific view
  • How to listen to taps and get views using Accessibility in Android?
  • How do I make my iOS / Android apps compliant with Section 508 of the U.S. Rehabilitation Act?
  • Android accessibility service detect notification
  • AccessibilityNodeInfo - send text
  • Droid Accessibility - Disable TalkBack for specific TextView
  • Related posts:

    Highlight ListView selected row
    Overriding onOptionsItemSelected from SherlockFragmentActivity
    Android: How to set a generated contextMenu title?
    How to findViewById() an @android:id/list element in an Android activity?
    Didn't find class on path: dexpathlist
    How to record voice in “wav” format in Android
  • How to start AccessibilityService?
  • How to access html content of AccessibilityNodeInfo of a WebView element using Accessibility Service in Android?
  • AccessibilityNodeInfo - send text
  • Set text in AccessibilityNodeInfo
  • How to use Accessibility Services for “Taking Action for Users”?
  • Programming for Android as a blind person
  • One Solution collect form web for “Detect if my accessibility service is enabled”

    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.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.