WakeLock 似乎没有按计划工作
我试图在应用程序发送通知时打开屏幕。目前,当我获取
一个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"); }
}
I'm trying to turn the screen on when the app sends a notification. Currently when I acquire
a WakeLock
it flashes on and off very quickly, almost un-noticeably. As far as I can tell I have my flags set correctly. AQUIRE_CAUSES_WAKEUP
to turn the screen on and ON_AFTER_RELEASE
to (poke the user activity timer) leave it on once I release it - otherwise, I understand it turning itself off immediately... Anyone got an insight?
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"); }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您设置
mTurnScreenOn
值的位置,查看您在mTurnScreenOn==true
时获取唤醒锁的代码,并且在相同条件下您也释放它。有关详细信息,请参阅此
where you are setting the value of
mTurnScreenOn
, Look at your code you are acquiring wake lock whenmTurnScreenOn==true
and on same condition your are releasing it also.for more info see this