How to detect network in Blackberry 10 Dev Alpha Simulator using qnx.net.NetworkManager on Air SDK

南笙酒味 提交于 2019-12-10 22:18:59

问题


I'm trying to detect internet connection of the simulator using this code

if (
    NetworkManager.networkManager.isConnected(NetworkType.WIFI) ||
    NetworkManager.networkManager.isConnected(NetworkType.CELLULAR)
) {
    //we have connection!!
    doSomething();
} else {
    //no connection =(
    showError();
}

However, this always returns false. It seems that the simulator uses another kind of network not identified by NetworkType constants. I think this happens because VMWare makes connection possible through black magic.

So i am not sure if I should stick to this code and hope it will work in a real device using WiFi or Cellular network, or should find another approach for what I need.

I've also tried doing this (passing no parameters)

NetworkManager.networkManager.isConnected()

but it will always return true despite if I have internet connection or not in my PC. I think VMWare is trolling me again.

So, any advice on how should I do this for better results in a real device?


回答1:


Well, just to update. I finally got a BBZ10, and had a chance to try this code. It seems that NetworkManager.networkManager.isConnected(NetworkType.WIFI) and NetworkManager.networkManager.isConnected(NetworkType.CELLULAR) will work the way they are expected, even if the emulator can't really emulate their funcionality.

So, if you really need this functionality, go ahead and try this, it WILL really work once deployed.



来源:https://stackoverflow.com/questions/14193870/how-to-detect-network-in-blackberry-10-dev-alpha-simulator-using-qnx-net-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!