简体   繁体   English

检查 BIND_ACCESSIBILITY_SERVICE 的权限

[英]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:我已经通过以下方式完成了所有工作:

  • Adding permission to my service in manifest.xml在 manifest.xml 中添加对我的服务的权限
  • Extending AccessibilityService and overriding onAccessibilityEvent扩展 AccessibilityService 并覆盖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.

相关问题 如何在 Android 中检查其他应用程序是否使用辅助功能(BIND_ACCESSIBILITY_SERVICE)权限 - How to Check other apps are using accessibility (BIND_ACCESSIBILITY_SERVICE) permission or not in Android 如果用户授予 BIND_NOTIFICATION_LISTENER_SERVICE 权限,如何检查 - How to check, if user granted BIND_NOTIFICATION_LISTENER_SERVICE Permission 授予可访问性服务权限以进行调试 - Granting accessibility service permission for debug purposes 使用LocationManager的服务检查权限 - Service with LocationManager check for permission HCE服务和BIND_NFC_SERVICE权限 - HCE service and BIND_NFC_SERVICE permission 启用无障碍服务但在运行时禁用对应用程序的权限时会发生什么,无障碍服务事件会发生什么 - what happen when accessibility service is enabled but the permission on app is disabled at runtime, what happen to the accessibility service events 仅在授予许可后如何绑定服务? - How to bind service only after permission is granted? 在Service中动态检查调用者权限 - Check caller permission dynamically in Service 在 Android 中不需要 android.permission.BIND_JOB_SERVICE 权限 - Does not require android.permission.BIND_JOB_SERVICE permission in Android android.permission.BIND_TELECOM_CONNECTION_SERVICE 权限被拒绝 - android.permission.BIND_TELECOM_CONNECTION_SERVICE permission denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM