问题
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