Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
malcolm
Posts: 41
Registered: ‎08-01-2008
My Device: Not Specified
Accepted Solution

Detecting when Wi-Fi is being turned off?

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.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Detecting when Wi-Fi is being turned off?

WLANConnectionListener?  Not tried this myself, but looks like it might do what you want.
Please use plain text.
Developer
malcolm
Posts: 41
Registered: ‎08-01-2008
My Device: Not Specified

Re: Detecting when Wi-Fi is being turned off?

[ Edited ]

**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()
*** saveRadioState(1)

 

..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..

Message Edited by malcolm on 09-10-2008 07:51 AM
Message Edited by malcolm on 09-10-2008 08:03 AM
Please use plain text.