失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Android 屏幕常亮

Android 屏幕常亮

时间:2024-04-25 16:46:07

相关推荐

Android 屏幕常亮

本文主题:

使android程序运行过程中,屏幕背景灯保持唤醒,即不黑屏。

先上代码:

注意需要加权限

[html]view plain copy<uses-permissionandroid:name="android.permission.WAKE_LOCK"/>

[java]view plain copy/** * *@authorzhujianbin * */ publicclassUtils{ privatestaticWakeLockwl; /** *保持屏幕唤醒状态(即背景灯不熄灭) *@paramon是否唤醒 */ publicstaticvoidkeepScreenOn(Contextcontext,booleanon){ if(on){ PowerManagerpm=(PowerManager)context.getSystemService(Context.POWER_SERVICE); wl=pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE,"==KeepScreenOn=="); wl.acquire(); }else{ wl.release(); wl=null; } } }

解释:

用到的类

PowerManager

主要是这两个参数:PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE

下面是 android 官方API解释:

he following flags are defined, with varying effects on system power. These flags are mutually exclusive - you may only specify one of them.

一般要使程序运行过程中背景保持常亮,使用

SCREEN_BRIGHT_WAKE_LOCK 就可以,

SCREEN_BRIGHT_WAKE_LOCKCPU:唤醒 屏幕背光:唤醒 键盘灯:关闭

第二个参数:

In addition, you can add two more flags, which affect behavior of the screen only.These flags have no effect when combined with aPARTIAL_WAKE_LOCK.

如果觉得《Android 屏幕常亮》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。