如何保持Android设备进入休眠状态,而在插 [英] How to keep android device from sleeping while plugged in

查看:304
本文介绍了如何保持Android设备进入休眠状态,而在插的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保持每当我活动之一,正在运行的手机插在电源上的画面。我知道Wakelocks是棘手,所以我在寻找一个例子或如何完成这样的目标一些文档。

I'd like to keep the screen on whenever one of my Activities are running and the phone is plugged in to a power source. I know that Wakelocks are tricky, so I'm looking for an example or some documentation on how to accomplish this specific goal.

推荐答案

不要使用唤醒锁本 - 刚刚成立,并清除窗口标志 WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 基于设备是否在当前已插入,你可以设置标志和 Activity.getWindow()。addFlags()

Don't use wake locks for this -- just set and clear the window flag WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON based on whether the device is currently plugged in. You can set the flag with Activity.getWindow().addFlags().

所以,code会

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

这篇关于如何保持Android设备进入休眠状态,而在插的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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