强制 Android 手机进入睡眠状态以进行测试?
我正在编写一个依赖于网络活动的 Android 应用程序,并且警报管理器有时会将手机从睡眠状态唤醒。
我的问题是如何在设备上可靠地测试它?理想情况下,我怎样才能强制手机进入完全睡眠状态。否则,我如何确定手机何时完全进入睡眠状态?
如何测试您的警报管理器/唤醒锁/睡眠处理代码?
I'm writing an android application that depends on network activity and the alarm manager sometimes waking the phone up from a sleeping state.
My question is how can I reliably test this on device? Ideally, how can I force the phone into a full-on sleeping state. Failing that, how can I know for sure when the phone has fully gone to sleep?
How do you test your Alarm Manager / Wake Lock / Sleep handling code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
关闭设备/模拟器的屏幕,然后运行以下命令:
重新运行第二个命令,直到收到消息“IDLE”。这适用于运行 Android 6.0 或更高版本的设备。
Turn off the screen of the device/emulator and then run the following commands:
Re-run the second one until you get the message "IDLE". This works on devices running Android 6.0 or newer.
步骤 1
在设置中将设备设置为“正在放电”(按照红框中的说明进行操作)。
b.按“电源”按钮(蓝色框)关闭设备屏幕。
第 2 步
要直接将设备置于睡眠模式,请运行:
adb shell dumpsys deviceidle force-idle
或者慢慢进入睡眠模式,
多次运行:
adb shell dumpsys deviceidle step
。步骤 3
要确认设备空闲状态,请运行:
adb shell dumpsys deviceidle get deep
Step 1
a. Put the device to "discharging" in settings (follow instructions in the red boxes).
b. Turn off the device screen by pressing the "power" button (blue box).
Step 2
a. To directly put the device to sleep mode, run:
adb shell dumpsys deviceidle force-idle
b. Or slowly step into sleep mode, run:
adb shell dumpsys deviceidle step
multiple times.Step 3
To confirm device idle status, run:
adb shell dumpsys deviceidle get deep
按下设备上的电源按钮应使其进入睡眠状态。还有一个 goToSleep(long time) PowerManager 中的方法,但这需要 DEVICE_POWER 权限,为系统应用程序保留。
Pressing the power button on the device should put it to sleep. There is also a goToSleep(long time) method in the PowerManager, but that requires DEVICE_POWER permission, which is reserved for system applications.
如果您想在模拟器上进行测试,请从主屏幕按
菜单->设置->应用->开发->取消选中保持清醒
if u want to test on the emulator then from home screen press
menu -> setting -> applications -> development ->uncheck stay awake