0

I am using AccessibilityService to monitor notifications. I followed this and this. Finally, it works and I get to know about new notifications.

But, to Connect the AccessibilityService I need to ask user to enable it from the ACCESSIBILITY_SETTINGS, which I do this way:

Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);

But, the problem is I want to check if the user has enabled it (AccessibilityService) or not. Also, I don't what to ask users again to enable it if they have already enabled it. So, is it possible to do this?

Community
  • 1
  • 1
abhi
  • 1,412
  • 19
  • 25

1 Answers1

1

You can test whether the user has enabled your Accessibility Service by checking the secure settings. Settings.Secure.getString() will give you a : separated list of enabled services, and you can check whether yours is in there. Something like this:

ComponentName compName = new ComponentName(context, MyAccessibilityService.class);
String flatName = compName.flattenToString();
String enabledList = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
boolean isEnabled = enabledList != null && enabledList.contains(flatName);
Steve Blackwell
  • 5,904
  • 32
  • 49