我如何可以通过编程解锁屏幕的Andr​​oid?

问题描述:

我工作的基础上JUnit的远程自动化测试框架为Android(测试运行的Andr​​oid之外,与code里面交互)。这一切都工作得相当好,但有一个问题我有是,当我自动启动一个新的仿真器,画面开始时锁定。这似乎影响到我的测试能够运行,再加上,我想看运行测试(点击按钮,文字输入等)。如果我手动启动仿真器和解锁其屏幕,一切运作良好。

I am working on a remote automated test framework for Android based on JUnit (tests run outside android, interacting with code inside it). It's all working fairly well, but one issue I have is that when I automatically start a fresh emulator, the screen starts out locked. This appears to affect my tests being able to run, plus, I want to watch the tests run (buttons clicked, text typed, etc.). If I manually start an emulator and unlock its screen, all works well.

有没有一种方法以编程方式解锁Android的屏幕?一个Java API,命令行或shell命令等等都将是罚款。除非,也许有一种方法来启动仿真器解锁?

Is there a way to programmatically unlock the screen in Android? A Java API, a command line or shell command, etc. would all be fine. Barring that, perhaps there is a way to start an emulator unlocked?

您可以通过它的控制台界面

如果你有没有想过为什么你的模拟器开始与一些像5554 - 这是因为这是该端口的仿真器监听

If you ever wondered why your emulator started with a number like 5554 - that's because that's the port the emulator listening on.

您可以找到端口与 ADB设备命令运行模拟器。这将有类似这样的输出:

You can find the port for running emulators with the adb devices command. It will have output like this:

C:\>adb devices
List of devices attached
emulator-5554   device

所以,你可以使用下面的命令连接仿真器:

So you can connect to the emulator using a command like:

telnet localhost 5554

如果你连接成功,你会得到一个确定提示符下,你可以开始输入命令。

If you connect successfully you'll get an OK prompt and you can start entering commands.

有不同的命令,但一个我们感兴趣的是事件来模拟硬件事件。

There are various commands but the one we are interested in is event to simulate hardware events. We can unlock the screen by pressing Menu which we emulate with the following command:

event send EV_KEY:KEY_MENU:1 EV_KEY:KEY_MENU:0

EV_KEY:KEY_MENU:1 是按键按下事件和 EV_KEY:KEY_MENU:0 是对应的关键事件的方式。确保你做双方或菜单键会被卡住。

The EV_KEY:KEY_MENU:1 is key-down event and the EV_KEY:KEY_MENU:0 is the corresponding key-up event. Make sure you do both or the Menu key will be stuck down.

我知道脚本,这将是远非易事,但它是所有我能想到的解决你的问题。

I realise scripting this will be far from easy, but it's all I can think of to solve your problem.

编辑:我不认为事件发送EV_KEY:KEY_MENU:1 EV_KEY:KEY_MENU:0 是模仿菜单大骨节病>但是,如果我跑我已经开始了它的确实仿真器刚过命令EM>解锁。不知道为什么,但我想这是一个开始。

I don't think event send EV_KEY:KEY_MENU:1 EV_KEY:KEY_MENU:0 is emulating Menu but if I run the command just after I've started the emulator it does unlock it. Not sure why but I guess this is a start.