如何获取android.app.UiAutomation的实例

ale*_*_au 6 android ui-automation android-uiautomator android-5.0-lollipop

我正在测试Android 5.0的一些新功能,现在是实现的一轮UiAutomator和新方法.我试图搜索一个示例/指南,然后我试图得到一个UiAutomator的实例

getSystemService()
Run Code Online (Sandbox Code Playgroud)

但那没有用.我的目标是使用executeShellCommands(String str).

有人已经实施了吗?

All*_*air 5

澄清一下,UiAutomation 类不是 UiAutomator 的一部分(尽管它们具有相似的名称)。

您可以通过调用Instrumentation#getUiAutomation()来获取 UiAutomation 实例 。这仅在您运行基于仪器的测试时才有效。

如果这是基于 shell 的 UiAutomator 测试的一部分,那么您可以使用Runtime#exec()来执行 shell 命令。