我正在尝试在应用发送通知时打开屏幕。目前,当acquire
WakeLock
时,它会快速闪烁,几乎不显眼。据我所知,我的旗帜设置正确。 AQUIRE_CAUSES_WAKEUP
打开屏幕并ON_AFTER_RELEASE
启用(戳用户活动计时器),一旦我将其释放,请将其保持打开状态 - 否则,我明白它会自动关闭..任何人都有洞察力?
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "TAG");
if(mTurnScreenOn) {
wl.acquire();
Log.d("TAG", "WakeLock Acquired");
if(pm.isScreenOn()) { Log.d("TAG", "Screen is on");
} else { Log.d("TAG", "Screen is off"); }
}
mNotificationManager.notify(1, notification);
if(mTurnScreenOn) { //release the wakelock if needed
wl.release();
Log.d("TAG", "WakeLock Released");
if(pm.isScreenOn()) { Log.d("TAG", "Screen is on");
} else { Log.d("TAG", "Screen is off"); }
}
答案 0 :(得分:0)
您要设置mTurnScreenOn
的值,请查看您在mTurnScreenOn==true
时获取唤醒锁定的代码,并且在相同条件下您也将释放它。
有关详细信息,请参阅this