netflix或Google之类的视频播放器如何显示/隐藏视频播放器控件?

问题描述 投票:2回答:1

我正在开发一个供自己使用的小项目,我需要我的辅助功能服务才能在屏幕上轻按并显示/隐藏Netflix或youtube等视频播放器的控件。

因此,在我的accessibilityService中,我使用getRootInActiveWindow(),并获得对应用程序窗口的引用(例如,com.netflix.mediaclient)

然后遍历所有节点,然后进行performAction(AccessibilityNodeInfo.ACTION_CLICK),但似乎没有一个节点是可单击的(当媒体播放器控件被隐藏时,否则我可以单击控件按钮),并且我无法制作媒体播放器控件显示出来。

知道为什么会这样吗?另外,是否可以在屏幕上总体上而不是在特定的AccessibilityNodeInfo上执行点击?

android android-accessibility
1个回答
0
投票

我无法使视频播放器控件通过可访问性节点显示,但我仅通过使用以下代码模仿屏幕上的点击,就能够达到类似的效果。

private void click(int x, int y) {
    Path path = new Path();
    path.moveTo(x, y);
    path.moveTo(x+10, y+10);
    GestureDescription.Builder builder = new GestureDescription.Builder();
    GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 10, 200)).build();
    dispatchGesture(gestureDescription, null, null);
}

然后我用诸如300、300之类的名称调用click函数

请确保放置

android:canPerformGestures="true"

在您的AccessibilityService XML文件中。

我仍然很好奇为什么我无法在节点上实现同样的效果,所以如果有人知道,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.