【发布时间】:2012-05-15 14:58:30
【问题描述】:
当手机进入睡眠/省电模式时,我的 Android 应用程序的一些用户报告了错误。
我想在 Android 虚拟设备上测试该问题。是否可以在 AVD 上模拟手机进入睡眠/省电模式?
提前致谢。
【问题讨论】:
-
我查看了其他 question,但答案似乎与锁定手机有关 - 我想将其切换到睡眠模式。
标签: android android-emulator avd
当手机进入睡眠/省电模式时,我的 Android 应用程序的一些用户报告了错误。
我想在 Android 虚拟设备上测试该问题。是否可以在 AVD 上模拟手机进入睡眠/省电模式?
提前致谢。
【问题讨论】:
标签: android android-emulator avd
【讨论】:
模拟器旁边边栏上的Power Button 可以做到这一点。
我的 Mac 上的热键是 ⌘ P
注意:您需要使用滑动而不是无设置锁定屏幕
【讨论】:
⌘ P再次解锁。
要使用命令行使设备进入睡眠状态,请运行:
adb shell input keyevent 223
要使用命令行将设备从睡眠中唤醒,请运行:
adb shell input keyevent 224
有关您可以通过 ADB 发送的关键事件的更多信息,请查看 KEYCODE_... 常量 KeyEvent,例如:
/** Key code constant: Sleep key.
* Puts the device to sleep. Behaves somewhat like {@link #KEYCODE_POWER} but it
* has no effect if the device is already asleep. */
public static final int KEYCODE_SLEEP = 223;
/** Key code constant: Wakeup key.
* Wakes up the device. Behaves somewhat like {@link #KEYCODE_POWER} but it
* has no effect if the device is already awake. */
public static final int KEYCODE_WAKEUP = 224;
【讨论】:
不知何故 fn + F7 在我的 mac 上不起作用。所以我改用的是:
adb shell input keyevent 26
这会发送 POWER KEY 事件并关闭屏幕。注意:它不会显示屏幕已关闭。图像将保留。但是你不能与之交互。再次adb shell input keyevent 26 后,您将看到锁定屏幕显示设备之前已关闭。
【讨论】:
通过按 F7 ,您可以在模拟器中模拟睡眠模式。
【讨论】: