[英]Check Permission for BIND_ACCESSIBILITY_SERVICE
I'm working on a Android App that needs to use the Android Accessibility Service.我正在开发一个需要使用 Android 无障碍服务的 Android 应用程序。
I've got it all kind of working by:我已经通过以下方式完成了所有工作:
onAccessibilityEvent
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
.但是,当我尝试检查用户是否启用了可访问性设置/权限时,通过调用
checkSelfPermission
,它总是返回“-1”,也就是BIND_ACCESSIBILITY_SERVICE
PERMISSION_DENIED
。
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? AccessibiliyService 是特例,不能正常检查权限吗?
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.我可以通过在我的 AccessbilityService 第一次运行时设置一个静态变量
running=true
来解决这个问题,但这感觉有点混乱。
Thanks in advance, I've been struggling with this for 1/2 the day :(提前致谢,我每天都为此苦苦挣扎了 1/2 :(
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.我打算检查辅助功能服务“权限”以查看用户是否已经启用它,如果没有,正确提示用户他们需要通过设置启用。
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).
它在服务标签中声明,以确保只有 Android 系统可以绑定到它(并禁止任何其他 3rd 方应用程序绑定到它)。
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有关 AccessibilityService 的更多信息,请查看文档: 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.
据我所知,它不能通过 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
可以在此处找到一些解决方法: 检测我的辅助功能服务是否已启用和此处: Android:如何检查特定的 AccessibilityService 是否已启用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.