三星 Galaxy Tab 中的唤醒锁定

发布于 2024-11-08 04:04:48 字数 603 浏览 0 评论 0原文

我正在开发一个应用程序,我需要在后台发送和接收数据包。但我发现,当屏幕关闭时,CPU 和网络也会被禁用。所以我在 Android Developers 上发现我应该使用唤醒锁和 wifi 锁来让 cpu 在屏幕关闭时继续工作。此解决方案适用于其他设备,例如 LG Optimus One,但不适用于三星 Galaxy Tab。使用此设备,当屏幕关闭时,我无法接收更多数据包(UDP),并且神奇的是,当我按下电源按钮重新启用屏幕时,我重新启动以接收数据包。 在我的代码中,我调用:

powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_W AKE_LOCK, "TAG");

然后

wakeLock.acquire();

我认为这是三星的错误,但我不确定这一点,如果有人能给我一些提示,我将非常感激。

PS我需要一些编程帮助...我已经知道,如果我修改一些手动设置以避免关闭屏幕,这将会起作用。但我正在开发一个应用程序,我需要代码!

I am developing an app in which i need to send and receive packets in background. But I've discovered that when screen shut off also cpu and networking is disabled. So I've found on Android Developers that I should use wake lock and wifi lock to let the cpu works altought if the screen went off. This solution works for other devices such LG Optimus One but not for Samsung Galaxy Tab. With this device when screen shut off I can't receive no more packets (UDP) and magically when I press power button for re enabling screen, I restart to receive packets.
In my code I call:

powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_W AKE_LOCK, "TAG");

then

wakeLock.acquire();

I think that is a Samsung bug but I'm not sure of this, and if someone can give me some hint i would really appreciate.

P.S. I need some programming help... I already know that if I modify some manual setting to avoid shutting down the screen, this will work. But I'm developing an app and i need code!!

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

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

发布评论

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

评论(2

一杆小烟枪 2024-11-15 04:04:48

在您的情况下,您应该使用PARTIAL_WAKE_LOCK

我不确定为什么 SCREEN_DIM_WAKE_LOCK 不够(没有找到任何证明这一点的文档),但是 PARTIAL_WAKE_LOCK 在类似的情况下对我来说工作得很好。

作为另一种选择,您可以使用 WifiLock< /a>.但您需要对此保持警惕,因为您的网络连接可能是 2G 或 3G,而不仅仅是 Wi-Fi。因此,当您实际使用 3G/2G/等时,不应该保持 Wi-Fi 锁定。

You should use PARTIAL_WAKE_LOCK in your case.

I'm not sure why SCREEN_DIM_WAKE_LOCK is not enough (didn't find any documentation that justifies this), but PARTIAL_WAKE_LOCK worked just fine for me in a similar scenario.

As another option you may use WifiLock. But you need to be smart about that, as your network connection may be 2G or 3G, not Wi-Fi only. So you shouldn't hold Wi-Fi lock when you are actually using 3G/2G/etc.

慵挽 2024-11-15 04:04:48

您可能还想检查高级 WIFI 设置。
在首选项 - WIFI 设置中,您可以按菜单键,单击高级图标,然后检查 WIFI 睡眠策略的值。选项之一是“屏幕关闭时”。

You might also want to check the advanced WIFI settings.
In Preferences - WIFI settings, you can hit the menu key, click the advanced icon, and check the value for WIFI Sleep policy. One of the options is "When screen turns off".

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