作者:奥奥奥尼瀚 | 来源:互联网 | 2022-03-04 14:20
方法一:
代码如下:
代码如下:
private PowerManager powerManager = null;
private WakeLock wakeLock = null;
powerManager = (PowerManager) this.getSystemService(Service.POWER_SERVICE);
wakeLock = this.powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Lock");
//是否需计算锁的数量
wakeLock.setReferenceCounted(false);
//请求常亮,onResume()
wakeLock.acquire();
//取消屏幕常亮,onPause()
wakeLock.release();
方法二:
直接在onCreate()里,不用权限
代码如下:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);