如何判断手机是否连接到 WiFi 网络或手机网络?
我正在开发一个应用程序,该应用程序应该根据用户是通过 wifi 还是其蜂窝网络发送请求而表现不同。如何检测手机连接的是哪个网络?
此答案黑莓论坛看起来很有前途,但我不确定知道 wifi 是否打开是否等同于知道将发送哪些网络请求。
(如果重要的话,我们的目标是 4.3+ 版本。)
I'm working on an app that should behave differently depending on whether a user is sending requests through wifi or their cell network. How can I detect which network the phone is connected to?
This answer on the BlackBerry Forums looks promising, but I am not sure if knowing if wifi is turned on is equivalent to knowing which network requests will be sent over.
(We are targeting versions 4.3+, if it matters.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导入 net.rim.device.api.system.WLANInfo。之后检查如下:
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
/* 无线局域网已连接 */
如果
已连接,请求将通过 WiFi 发送。
Import net.rim.device.api.system.WLANInfo. After that check as follows:
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
/* wlan connected */
}
If it is connected, requests will be sent via WiFi.