android 唤醒屏幕

权限还是要给的

    

代码如下

 PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
 if(!screenOn){//如果是熄灭状态
            final PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "TAG");
            wakeLock.acquire();//亮屏
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    wakeLock.release();//熄灭
                }
            },5*1000);//5秒
        }

你可能感兴趣的:(android 唤醒屏幕)