09-10-2008 06:55 AM
I'd like to know if there is a way in OS 4.3 to detect that a user has selected to turn off the Wi-Fi on the Manage Connections screen? It would be really useful if I could listen for a message indicating this event, and manually close the TCP connections I have opened across Wi-Fi. Currently (I can only test on the simulator at the moment as I don't have any devices with Wi-Fi to hand) it appears that if you turn off Wi-Fi neither the server application (running on the blackberry) nor the remote client notice the connection has closed. No exceptions are thrown, except eventually timeouts.
I don't know if there is any interface to track Wi-Fi messages - I looked at RadioStatusListener but none of the methods or fields defined appeared to refer to Wi-Fi. Ideally I would like to be able to manually call close() on the outputstream as Wi-Fi is about to close so that the client fails gracefully, and the server can identify and remove the client thread. Is there any way to do this? Or does this all happen differently on actual devices
Thanks in advance.
Solved! Go to Solution.
09-10-2008 07:19 AM - edited 09-10-2008 08:03 AM
**bleep**, I thought I had checked through all the *Listener classes, clearly not that thoroughly. This looks like it will probably do the trick, so thankyou!
edit: Hmm, this is very odd. I have implemented the Listener class and added it with WLANInfo.addListener(...) but neither the method networkConnected nor networkDisconnected is ever called in the simulator. I still receive messages like this on the JDE debug output when I turn the WiFi on or off:
*** WLAN radioTurnedOff()
..But it seems the notification mechanism doesn't work, either that or I've misunderstood how it's supposed to be used in some way.
Edit again: Okay, seems like the listener mechanism is called, but not necessarily when turning the radio off or on, more when connecting to a specific network. This is a little confusing but dealable with..