简体   繁体   English

在Android Studio中运行/调试程序时唤醒设备?

[英]Wake up device when program is run/debugged in Android Studio?

Most of my development devices have OLED displays, so they can't safely have "Stay Awake" enabled under "Developer Options" (I've ruined WAY too many devices using it in the past). 我的大多数开发设备都具有OLED显示屏,因此不能安全地在“开发人员选项”下启用“保持唤醒”状态(过去我已经淘汰了太多使用它的设备)。 But having to continuously keep picking up the device to hit the power button every time I re-launch something within Android Studio is driving me insane. 但是每次我在Android Studio中重新启动某些功能时,都必须不断地拿起设备以按电源按钮,这让我发疯了。

Is there any way to configure the devices and/or Android Studio to allow the screen to time out and turn off as usual, but automatically turn it back on again whenever I do something via ADB? 有什么方法可以配置设备和/或Android Studio,以允许屏幕超时并照常关闭,但是每当我通过ADB做某事时自动将其重新打开?

For what it's worth, I tried disabling lockscreen security, but launching a program or debugging session via shift-f9 or shift-f10 while the screen of the ADB-connected device is off still fails to turn it on. 出于其价值,我尝试禁用锁屏安全性,但是在连接ADB的设备的屏幕关闭时通过shift-f9或shift-f10启动程序或调试会话仍然无法将其打开。

Before starting the app, run 在启动应用程序之前,运行

adb shell input keyevent KEYCODE_POWER

to wake up the device 唤醒设备

write this code in Oncreate and before Setcontentview : 在Oncreate和Setcontentview之前编写以下代码:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

screen will never sleep with this code. 屏幕永远不会用此代码休眠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM