Make silent connection
I'm want to use ConnectivityManager inorder to 开发者_如何转开发find an appropiate network and then create a socket that will use that network. Is it possible to "bind" a socket to a specified hotspot?
Thanks, Nahum
You bind sockets when you want to your program to send/receive data on a specific IP or interface. Socket binding is commonly used when you have multi-honed hosts, ie. a computer with 2 nics.
With Android you really dont need to do any binding because you can't actually have the wifi interface and the cell interface up at the same time (Android will cut the cell's data interface off when wifi turns on.)
The one exception to this would be if you are using VPNs on android, in which case the binding interface comes into play if you want to send/receive data using the VPN network instead of the cell/wifi network.
All that being said, binding really doesn't have anything to do with the wifi hotspot you are connected to. Binding occurs at the IP (network) level, and hotspot identification level (MAC [link].)
You could ID the hotspot and block send/receive though:
ways for a client to identify the specific access point it is connected to within a single SSID?
-- Dan
Edit: This other post might be helpful: Determining Android VPN Interface/IP?
There really aren't many networks to choose from for binding.
If you actually want to tell Android which Access Point to connect to (which has nothing to do with binding), then you can use the WifiManger:
http://developer.android.com/reference/android/net/wifi/WifiManager.html
Just call enableNetwork with the network you want to connect to.
精彩评论