首页 > 解决方案 > 为什么我的无障碍服务要求全屏控制?

问题描述

我有以下可访问性配置文件,其中禁用了窗口检索,我只想过滤关键事件:

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityFlags="flagRequestFilterKeyEvents"
    android:canRequestFilterKeyEvents="true"
    android:canRequestTouchExplorationMode="false"
    android:canRetrieveWindowContent="false"
    android:description="@string/permissions_accessibility_description"
    android:settingsActivity="" />

但是,Android 一直说我想阅读屏幕上的内容并在其他应用程序上显示内容:

在此处输入图像描述

有什么办法可以摆脱我根本不感兴趣的“查看和控制屏幕”警告?

标签: androidandroid-serviceandroid-accessibility

解决方案


I was curious about this as well, because I am writing an accessibility service that does not "view" or "control" the screen in any way, requests no such permissions in the AndroidManifest.xml file, and was therefore surprised by this seeing this dialog for my service.

It turns out that this dialog is shown for your AccessibilityService because the dialog is essentially hard-coded to appear when enabling any accessibility service.

It would be reasonable if the Android documentation mentioned this in any way, or explained to developers why the dialog appears, but the Android documentation does not.

If we explore the source code of this screen, there are 3 cases for issuing the (same) warning for enabling the service, 1 case for issuing a warning when disabling the service, and a default case (which is likely there as a "good practice" for Java code, and that I doubt is ever actually executed as code).

It is not a "real" solution, but as a compromise, we can always mention the description XML attribute of the accessibility-service XML tag that Android is flat-out lying about our apps needing any (or all) of these functionalities, link to our source code, etc.


推荐阅读