Skip to content

Instantly share code, notes, and snippets.

@skounis
Last active December 18, 2015 08:26
Show Gist options
  • Save skounis/d1391ca15fe852a39a4a to your computer and use it in GitHub Desktop.
Save skounis/d1391ca15fe852a39a4a to your computer and use it in GitHub Desktop.
Network check workaround for android due to issue https://issues.apache.org/jira/browse/CB-10160
function getNetworkStatus() {
// On Android and when only the 3G interface is on
// the return connection type is `unknown` even the device is online.
// To work around this we will assume that only Connection.NONE
// is declaring an offline device. Which is returned when data are
// disabled.
var isPluginAvailable = !!navigator.connection;
if (isPluginAvailable) {
var networkState = JSON.stringify(navigator.connection); //.type
console.log('Internet connectivity chech. NetworkState: ' + networkState);
// HACK: this is a temporary hack due to Android 3G related issue
// described above.
if (navigator.connection.type.toLowerCase() == 'unknown'){
return true;
}else {
return $cordovaNetwork.isOnline();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment