处理 WiFi 断开连接的方法
在我的 Android 应用程序中,它是 注意到当设备进入睡眠/待机状态时 WiFi 已断开连接。当设备唤醒时,它会重新连接。在制作之前
httpClient.execute(..) 调用远程服务器,我们检查设备是否连接到网络。 当数据传输正在进行时,如果 设备进入睡眠状态,然后 Android 运行时将切换到另一个 连接媒介(3G、GPRS 等)。
- 是否从 WiFi 切换到备用蜂窝服务 说3G,无缝?
- 如何等待 WiFi 再次可用?当 WiFi 唤醒时我应该使用 Thread.sleep(delay) 吗?我见过 WiFi 状态改变时的广播动作。
一般来说,在移动应用程序中处理 WiFi 断开连接的理想方法是什么?
In my Android application, it is
noticed that when the device goes to sleep/standby WiFi is
disconnected. When the device wakes up, it gets reconnected. Before making a
httpClient.execute(..) call to remote server we check if the device is connected to n/w.
When the data transfer is being done and if
the device goes to sleep then Android runtime will switch to another
medium for connectivity(3G,GPRS etc.).
- Is the switch from WiFi to alternate cellular service
say 3G, seamless? - How do I wait for WiFi to become available again? Should I use Thread.sleep(delay) when the WiFi wakes up? I have seen broadcast actions when the WiFi state changes.
In general, what is the ideal approach to handling WiFi disconnects in a mobile app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不在传输发生时使用 WifiManager.WifiLock 并在完成后释放它。
我怀疑网络连接切换不会是无缝的。我不确定。
当 Wifi 连接状态发生变化时,BroadcastReceiver 会让您知道。不过,请查看 ConnectivityManager,因为它将监控 Wifi 和 GPRS 等,并且它确实会进行故障转移。虽然我不知道是否无缝。
Why not use WifiManager.WifiLock when the transfer is happening and release it when you have finished.
I would suspect network connection switch would not be seamless. I don't know for sure.
A BroadcastReceiver will let you know when Wifi connection state changes. Have a look at ConnectivityManager though because that will monitor Wifi and GPRS etc and it does do failover. Whether it is seamless though I don't know.