WakeLock 似乎没有按计划工作

发布于 2024-12-17 17:07:13 字数 950 浏览 2 评论 0原文

我试图在应用程序发送通知时打开屏幕。目前,当我获取一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰火雁神 2024-12-24 17:07:13

在您设置 mTurnScreenOn 值的位置,查看您在 mTurnScreenOn==true 时获取唤醒锁的代码,并且在相同条件下您也释放它。

有关详细信息,请参阅

where you are setting the value of mTurnScreenOn , Look at your code you are acquiring wake lock when mTurnScreenOn==true and on same condition your are releasing it also.

for more info see this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文