Android Froyo 和 Wifi

发布于 2024-09-09 03:31:25 字数 296 浏览 3 评论 0原文

默认情况下,Wifi 睡眠策略为“屏幕空闲时睡眠”。

有了这个策略,后台服务以后是否可以使用某些 API 来唤醒 Wifi?

我正在尝试以下操作,但不起作用: 当我的后台服务唤醒时,它会调用“ConnectivityManager.getActiveNetworkInfo()”来获取活动网络。 由于无线在空闲时关闭,我尝试在以前使用的 Wifi 连接上使用“WifiManager.startScan”将其唤醒。 但仍然无法连接 Wifi。

有什么想法吗? 我最好不想将我的睡眠策略更改为“从不”。

谢谢 赫曼特

By default, Wifi sleep policy is "Sleep on screen idle".

With this policy, is it possible for a Background Service at a later time to wake up Wifi using some API?

Am trying the following, but does not work:
When my Background Service wakes up, it calls "ConnectivityManager.getActiveNetworkInfo()" to get active network.
Since, the wireless is off on idle, I tried waking it up using "WifiManager.startScan" on a previously used Wifi connection.
But still dont get Wifi connectivity.

Any ideas?
I preferably do not want to change my sleep policy to "Never".

Thanks
Hemant

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

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

发布评论

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

评论(1

骄兵必败 2024-09-16 03:31:25

对此没有真正简单的解决方案。为了在手机/屏幕进入睡眠状态时确保您有 WIFI 连接,最好的方法是将其关闭。在这里查看很多细节 - http://wififixer.wordpress.com/

认识到这一点很重要在睡眠模式下,Wifi 会进入低功耗模式。然后以编程方式检查这将变得很棘手,因为它可能具有与 Wifi 的连接,但 Wifi 连接太弱或太慢而无法完成 HTTP 请求,因此会超时。这将迫使您还检查 Wifi 连接的速度,并且您将拥有一个活跃的网络,但网络非常糟糕。

当您进行的 HTTP 调用发生超时时,正确处理转义使其可以使用,但最终只有当您的 Wifi 模式从不休眠时,才有后台线程不断运行以获取数据的唯一方法。

这很棘手,而且不是我所知道的最好方法。 :-( 然而,这是我找到的唯一足够可靠的路径。

There are no real simple solutions for this. To with a high probability ensure you have WIFI connectivity when the phone/screen goes to sleep the best way is to turn it off. Look here for a lot of details - http://wififixer.wordpress.com/

It is important to realize that in sleep mode the Wifi enters a low power mode. This will become tricky then to programmatically check as it might have connectivity to the Wifi but the Wifi connection is too weak or too slow to complete the HTTP request and hence it times out. This would force you to also check the speed of the Wifi connectivity as well as you will have an active network but a pretty lousy one.

Proper handling of the escaping when timeout occurs for the HTTP call you make makes it ok to use but ultimately the only way to have a background thread constantly running to get data is only doable when you have the Wifi mode to never sleep.

It is tricky and not the best way I know. :-( It is however the only path I have found which is reliable enough.

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