允许在睡眠时使用 wifi 数据并唤醒设备

发布于 2024-10-19 18:10:05 字数 282 浏览 1 评论 0原文

我搜索并没有找到这个问题的答案。我正在开发可以一直运行的应用程序。我正在使用 wifi,一切正常,直到设备进入睡眠状态。一台设备发出多播数据包,另一台设备应该收到这些数据包并唤醒,但事实并非如此。现在,网络线程是从我的主类中的 StartService() 启动的服务线程启动的。在该服务中,我获得了 wifi 锁和 wifi 多播锁,以便 wifi 和多播“应该”在设备睡眠时保持打开状态。我还尝试在组合中添加部分唤醒锁,但仍然不起作用。有什么想法吗?我现在正在开发两个运行 android 2.3.3 的 Nexus 。

I searched and was not able to find the answer to this question. I am working on app that will run all the time. I am using wifi and everything works fine until the device sleeps. One device sends out multicast packets and the other one should get them and wake up but it is not. Right now the network thread is started from a service thread started by StartService() from my main class. IN the service I get a wifi lock and a wifi multicast lock so that wifi and multicast "should" stay on when the device sleeps. I also tried adding a partial wake lock to the mix but still nothing works. Any ideas? I am devleoping on two nexus ones running android 2.3.3 right now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

小巷里的女流氓 2024-10-26 18:10:05

您需要在 WakeLock 中设置 PowerManager.ACQUIRE_CAUSES_WAKEUP 标志,但是 PowerManager.ACQUIRE_CAUSES_WAKEUP 标志不能与 PowerManager.PARTIAL_WAKE_LOCK 一起使用,但它应该与 PowerManager.SCREEN_DIM_WAKE_LOCK 一起使用。
当您在 WakeLock 上调用 acquire() 时,下面的代码应该唤醒设备的显示屏和 CPU。 5 秒睡眠应该让您的 WiFi 有足够的时间唤醒。

WakeLock lock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
                    | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
lock.acquire();
try {
    Thread.sleep(5000);
} catch (InterruptedException e) {                  
}   
// do work here..
lock.release()

You need to set the PowerManager.ACQUIRE_CAUSES_WAKEUP flag in your WakeLock, however PowerManager.ACQUIRE_CAUSES_WAKEUP flag doesn't work with PowerManager.PARTIAL_WAKE_LOCK, but it should work with PowerManager.SCREEN_DIM_WAKE_LOCK.
Below code should wake the display and CPU of your device, when you call acquire() on the WakeLock. The 5 second sleep should give your WiFi enough time to wake.

WakeLock lock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
                    | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
lock.acquire();
try {
    Thread.sleep(5000);
} catch (InterruptedException e) {                  
}   
// do work here..
lock.release()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文