Reputation: 2256
I’m working on a Android App that needs to use the Android Accessibility Service.
I’ve got it all kind of working by:
onAccessibilityEvent
However when I try to check if the user has enabled Accessibilty Setting / Permission, by calling checkSelfPermission
, it always returns “-1” aka, PERMISSION_DENIED
for BIND_ACCESSIBILITY_SERVICE
.
Am i missing something?
Is it possible to check if a setting / permission is enabled or not?
Is AccessibiliyService a special case, and you can’t check permissions as normal?
I can possibly work around by setting a static variable running=true
in my AccessbilityService when it runs for the first time, but this feels a little messy.
Thanks in advance, I’ve been struggling with this for 1/2 the day :(
I’ve tried requesting permissions:
To clarify:
I was intending on checking the Accessibility Service "permission" to see if the user had enabled it already, and if not, correctly prompt the user that they need to enable via settings.
Upvotes: 0
Views: 6052
Reputation: 283
As far as I understand you don't need to check for this permission. It is declared in service tag to ensure that only Android system can bind to it (and prohibit any other 3rd party apps to bind to it).
Can I ask why do you want to check this permission as normal permission?
For more information about AccessibilityService please take a look into documentation: https://developer.android.com/guide/topics/ui/accessibility/service#manifest
Update after clarification:
Checking if your Accessibility Service is turned on by the user may be tricky. As far as I know it can't be done via Accessibility API. Some workarounds can be found here: Detect if my accessibility service is enabled and here: Android: How do you check if a particular AccessibilityService is enabled
Upvotes: 3