How to send key events to a headless emulator in an instrumentation test?

一世执手 提交于 2019-12-03 06:55:09

I had similar problem with my test on the Hudson server. In my case the problem I solved by suggestion from Android SDK: http://developer.android.com/guide/topics/testing/testing_android.html#UITestTroubleshooting

Important was that I had to enable permissions for main application too.

Christopher Orr

I run the emulator without -no-window on headless machines by first running an Xvnc instance (i.e. fake X server) then starting the emulator in that DISPLAY.

More accurately, I get the Xvnc and Android Emulator Jenkins plugins to do this for me.

Unfortunately, unlocking the screen is still a concern before injecting UI events, but this is (hackily) resolved by automatically running a command like this (similar to this other answer you've seen):
echo "event send EV_KEY:KEY_MENU:1 EV_KEY:KEY_MENU:0" | nc -q1 localhost 5554


Edit:
I discovered that this method is far more reliable:
adb shell input keyevent 82

Some info about keycode 82.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!