How to use AccessibilityService?

后端 未结 2 782
野趣味
野趣味 2021-02-10 15:51

I am studying AccessibilityService. I studied what is Accesibility Service and why we use it, what are advantages of Accessibility Service. So I tried to make a demo of Accessib

相关标签:
2条回答
  • 2021-02-10 16:43

    You can't "start" the AccessibilityService as they are not like other services where you can control their start/stop. Rather here the Android system controls starting and stopping them based on the settings the user has selected.

    The best you can do is launch the Accessibility settings page and get the user to enable it for you:

    Intent openSettings = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
    openSettings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(openSettings);
    

    Hope it helps!

    0 讨论(0)
  • 2021-02-10 16:43

    You are attempting to start your own AccessibilityService. That is not possible, as you cannot hold android.permission.BIND_ACCESSIBILITY_SERVICE. Moreover, it should not be necessary, as the system will start your service when appropriate (e.g., the user has enabled the service in Settings).

    If you have business logic in your AccessibilityService that you also want to use elsewhere, move it to some central spot that can be used by both the AccessibilityService and your other code.

    0 讨论(0)
提交回复
热议问题