Krosxx / Android-Auto-Api

安卓无障碍服务Api, 为了简化无障碍服务使用,并使用 Kotlin 以提供简洁的Api。
Apache License 2.0
418 stars 72 forks source link

发现了一个问题 #6

Closed BelongsH closed 3 years ago

BelongsH commented 3 years ago
 //适应 多窗口 分屏
    val rootNodeOfAllWindows
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ViewNode.withChildren(
                windows?.mapNotNull {
                    it.root?.let { r -> ViewNode(r) }
                } ?: emptyList()
            )
        } else {
            rootViewNode ?: ViewNode.withChildren(emptyList())
        }

Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP 以上的系统手机,

界面变化后,findFirst还是获取到上一帧的界面数据。

只有分屏的时候,界面才进行刷新。 (通过划出任务栏,无障碍才能获取到当前界面的数据)

同样的代码,在Android10(华为) 上面获取到的是上一帧的数据,在Android7(小米)上是正常的。

Krosxx commented 3 years ago

可以贴下动作代码吗,部分也可

BelongsH commented 3 years ago
 fun startTask2(loop: (str: String) -> Unit): Job {
        return launchWithExpHandler {
            runTask = true
            while (runTask) {
                val listView = withType("ListView").findFirst()
            }
        }
    }

获取到这个ListView在华为手机(Android 10)是上一帧的, 但是在小米手机(Android 7)上,就是当前帧。

Krosxx commented 3 years ago

@BelongsH 尝试下面方法, 或者 在while里 delay(200) 一下试试

fun startTask2(loop: (str: String) -> Unit): Job {
        return launchWithExpHandler {

            val listView = withType("ListView").await(15000)

        }
    }
BelongsH commented 3 years ago

我已经确定了问题了,

在断点之后发现onAccessibilityEvent没有被调用,而且仅仅在android 10上面才出现。

查看demo的配置文件后发现

 android:accessibilityEventTypes="typeWindowStateChanged"

这个配置在android 7 上面是有效的。

我尝试的将配置改成

    android:accessibilityEventTypes="typeAllMask"

这样就可以适配android 10