I would like to programmatically enable/disable Accessibility Services listed under Settings->Accessibility option.
I could start Accessibility Intent like below:
In instrumented tests I start my accessibility service like this:
private fun enableAccessibilityService() {
val packageName = "com.example"
val className = "$packageName.service.MyService"
val string = "enabled_accessibility_services"
val cmd = "settings put secure $string $packageName/$className"
InstrumentationRegistry.getInstrumentation()
.getUiAutomation(UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES)
.executeShellCommand(cmd)
.close()
TimeUnit.SECONDS.sleep(3)
}
I tested on Android 6 and 8. This also works for non-system apps.