07-12-2012 02:06 PM
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!
07-13-2012 04:49 AM
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??
07-13-2012 08:50 AM
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.
07-16-2012 10:20 AM
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/blackb
This should return true/false when WiFi is enabled/disabled.
07-19-2012 09:36 AM
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.
07-25-2012 08:52 AM
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!
07-25-2012 09:04 AM
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!
08-25-2012 04:32 AM
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..