让 Android 休眠以进行测试 [英] Put Android to sleep for testing

查看:43
本文介绍了让 Android 休眠以进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个闹钟应用程序,目前在处理唤醒锁(或者可能是其他问题)方面存在问题,以便在手机处于睡眠状态时使闹钟正常工作.然而,我的问题实际上并不是关于唤醒锁,而是关于如何让手机进入睡眠状态,以便我可以测试我想在我的闹钟应用程序上实现的各种选项.目前我必须等待手机进入睡眠状态才能测试我的代码.那么有没有办法以编程方式让手机进入深度睡眠?

I'm creating an alarm app and currently have issues dealing with the Wakelock (or perhaps it's something else), to make the alarms work when the phone is asleep. However, my question isn't actually about the Wakelock, but rather about how to make the phone go to sleep so I can test the various options I want to implement on my alarm app. Currently I have to wait for the phone to go to sleep before I can test my code. So is there a way to put the phone in deep sleep programmatically?

推荐答案

我在开发工作期间遇到了同样的问题.android 文档不是很有用——使用 adb 切换到打盹模式(深度睡眠):

I ran into the same question during my dev work. The android docs are not very useful -- use adb to switch into doze mode (deep sleep):

adb shell dumpsys deviceidle force-idle

同样有用,使用:

adb shell dumpsys deviceidle step

adb shell dumpsys deviceidle unforce

回到正常"模式.简介:

to get back to "normal" mode. Brief intro:

adb shell dumpsys -l  #(lower case "L") list subsystems (deviceidle is one)

然后:

adb shell dumpsys deviceidle -h  #parameters with brief description

此外,adb 需要访问您的设备(或模拟器)才能获取此信息.祝你好运!

Also, adb needs access to your device (or emulator) to get this information. Good luck!

这篇关于让 Android 休眠以进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆