2

Background

Suppose you have an app that has an accessibility service, and the user has enabled it after you've used the correct intent :

startActivity(new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS));

You can also check if the user has enabled it or not, using this code.

The problem

Sometimes, even if the user has enabled it, because it calls many times to onAccessibilityEvent, waking the app, it would be nice to be able to disable it temporarily.

What I've tried

I tried to disable the service as a component, but it works only after a few seconds for some reason:

private boolean isComponentEnabled() {
    final int componentEnabledSetting = getPackageManager().getComponentEnabledSetting(new ComponentName(this, ....class));
    return componentEnabledSetting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || componentEnabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
}

public void setEnabled(boolean enabled) {
    ComponentName component = new ComponentName(this, ....class);
    getPackageManager().setComponentEnabledSetting(component,
            enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}

Also, re-enabling the service doesn't do anything except changing its state to be enabled, meaning no calls to "onAccessibilityEvent" even though it's enabled.

The question

Is it possible to enable&disable this service programmatically, to avoid un-needed calls to "onAccessibilityEvent", and avoid performance issues from it?

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • Possible duplicate of [How to Programmatically Enable/Disable Accessibility Service in Android](http://stackoverflow.com/questions/10061154/how-to-programmatically-enable-disable-accessibility-service-in-android) – vault Jan 24 '17 at 16:47
  • @vault Not sure, but it seems they ask about how to get it before you've asked it from the user. I ask about how to disable&restore it temporarily, if it's even possible, after the user has enabled it. – android developer Jan 24 '17 at 19:42
  • Anyway, I've decided to post a request for this feature here: https://code.google.com/p/android/issues/detail?id=232858 – android developer Jan 24 '17 at 19:46

0 Answers0