Reputation: 1719
In my cordova-app running on an Android 5 device I need to know if a device goes offline. I am doing this according to the cordova-documentation:
document.addEventListener("offline", onOffline, false);
function onOffline() {
// Handle the offline event
}
For testing the code, I have connected my Android Device (which doesn't has mobile-data-connection) to a WIFI-access-point, which is connected to the internet.
As soon as I shutdown the WIFI-Access-point the Event "offline" gets fired, and my application knows about it. So far so good.
Unfortunately there is a use case in which this code-sample doesn't work:
Image the same situation: Android-Device is connected to a WIFI-access point, which is connected to the internet.
If I now disconnect the WIFI-access point (pull the LAN-cable), but leave the hotsport running, my cordova Application will never know about it. The user can't do the internet related things anymore (because there is no internet obviously), but the "offline" event never gets fired!
Is there a workarround for this? How can I check if the device lost internet-connection, if there is still an active WIFI-connection?
Upvotes: 2
Views: 760
Reputation: 1439
The plugin you're using is clearly not useful in your specific case. Anyway when you tell "The user can't do the internet related things anymore" what does it means? If there is no internet, you should receive "internet unavailable" answers from your APIs and check the errors in your ajax calls, if you use them. Checking this connection state, you can decide what to do
Upvotes: 1