权限还是要给的
<uses-permission android:name="android.permission.WAKE_LOCK" />
代码如下
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秒
}
网友评论