有些时候我们需要让手机处于 屏幕唤醒状态(屏幕不熄灭),这个时候我们就需要用到 PowerManager了,代码如下:
@Override
public void onResume() {
if(getActivity()!=null){
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);
// mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG);
// in onResume() call
mWakeLock.acquire();
}
super.onResume();
}
@Override
public void onPause() {
if(mWakeLock!=null){
// in onPause() call
mWakeLock.release();
}
super.onPause();
}