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

Web and WebWorks Development

Reply
New Developer
mrtrn
Posts: 30
Registered: ‎10-15-2008
My Device: Bold 9900

Checking for a WiFi connection with WebWorks

I must be missing something. I'm using the following to determine whether the device has a WiFi connection:

 

function onWiFi() {

var networkConnections = blackberry.network;

return (networkConnections.indexOf("Wi-Fi") != -1);

}

 

I ran this on my 9900 after I turned off my WiFi and it still returned true.

 

I logged the values of blackberry.network and it returns 3GPP,Wi-Fi whether the WiFi is on or not.

 

Am I missing something or do I misunderstand the documentation?

 

Thanks in advance!

Please use plain text.
Regular Contributor
BertKoor
Posts: 81
Registered: ‎03-09-2012
My Device: PlayBook & Bold 9780

Re: Checking for a WiFi connection with WebWorks

Documentation of blackberry.system.hasDataCoverage () mentions there can be a small delay (2-3 secs) between the time the device connects until the method returns true. I assume you waited longer than that.

 

If you also switch off 3G, what does blackberry.network return then??

Please use plain text.
New Developer
mrtrn
Posts: 30
Registered: ‎10-15-2008
My Device: Bold 9900

Re: Checking for a WiFi connection with WebWorks

That's an interesting idea. I turned off all connections and went to grab a coffee. I came back and ran the app again and it still insisted that I had a WiFi connection. The log shows blackberry.network returning 3GPP, Wi-Fi.

 

 

Please use plain text.
Retired
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Checking for a WiFi connection with WebWorks

The blackberry.network object is simply a string.  Unless you reload the page (and refresh the JavaScript runtime), its values does not dynamically change when you disable the radio.  So the behavior you have described is what I would expect to see if you remain on the same page when you switched out and disabled the WiFi radio.

 

Are you working in the browser, or a webworks application?  If the latter, an alternative solution could be to use the blackberry.system.hasCapability("network.wlan") method which should always return a live result:

https://developer.blackberry.com/html5/apis/blackberry.system.html#.hasCapability

 

This should return true/false when WiFi is enabled/disabled.

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.
New Developer
mrtrn
Posts: 30
Registered: ‎10-15-2008
My Device: Bold 9900

Re: Checking for a WiFi connection with WebWorks

Still no luck.

 

It's a WebWorks application.

 

I changed the code to output the results of blackberry.system.hasCapability("network.wlan")

 

I installed the app and turned off my WiFi on the 9900. I waited for two minutes and then started the app. 

 

blackberry.system.hasCapability("network.wlan") still returns true.

 

 

Please use plain text.
New Developer
MS-BMB
Posts: 8
Registered: ‎03-20-2012
My Device: Torch 9810, PlayBook

Re: Checking for a WiFi connection with WebWorks

Hi,

 

I have the same problem. To test my Wifi-connection after the Foreground-Event "app.event.onForeground" I use

 

 if (blackberry.system.hasCapability("network.wlan")) {
		 alert('connected')
		location.reload(true);} 
		else{
			alert('not connected')
		}

 It always return "true" as result even if I turn the wifi off.

I hope someone can give an advise to me.

 

Thank's!

 

Please use plain text.
New Developer
MS-BMB
Posts: 8
Registered: ‎03-20-2012
My Device: Torch 9810, PlayBook

Re: Checking for a WiFi connection with WebWorks

I have found the solution for my problem.

Now I use: 

 if (blackberry.system.hasDataCoverage()) {
		 
		location.reload(true);} 
		else{
			return Tryagain();
		}

 

It work's fine!

 

Please use plain text.
Trusted Contributor
NitishSubudhi
Posts: 166
Registered: ‎12-09-2011
My Device: 9550,9300,9800,9700,9900,9850,9860

Re: Checking for a WiFi connection with WebWorks

I think these code will help you:

if(!navigator.onLine)

here navigator.onLine returns True and !navigator.onLine returns false..

blackberry.system.hasDataCoverage()
for checking data coverage

blackberry.system.hasCapability("network.wlan")
for checking the string you have passes..

 

 

Thanks & Regards,
Nitish Subudhi

Feel Free To Press The Like Button On The Right Side To Thank The User That Helped You.
Please Mark Posts As Solved If You Found a Solution.
Please use plain text.