发布网友 发布时间:2022-04-30 03:45
共1个回答
热心网友 时间:2023-10-10 05:05
1.WakeLock主要代码如下:
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());//持有唤醒锁
wakeLock.setReferenceCounted(false);
wakeLock.acquire(30*1000);//30s亮屏
wakeLock.release();//释放锁,灭屏
2.FLAG_KEEP_SCREEN_ON代码如下
可使用 FLAG_KEEP_SCREEN_ON 替换WakeLock的方式.
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);//亮屏
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);//灭屏