Skip to content

Commit aa08a38

Browse files
committed
Merge pull request #16 from satsalou/issue-15
fix(internet-connectivity) Issue #15: Improve network connectivity on…
2 parents 7ec39e1 + 90fb7a7 commit aa08a38

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

app/scripts/config/internet-connectivity.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,30 @@
3535
};
3636

3737
function getNetworkStatus() {
38+
39+
// On Android and when only the 3G interface is on
40+
// the return connection type is `unknown` even the device is online.
41+
// To work around this we will assume that only Connection.NONE
42+
// is declaring an offline device. Which is returned when data are
43+
// disabled.
44+
3845
var isPluginAvailable = !!navigator.connection;
3946

4047
if (isPluginAvailable) {
41-
return $cordovaNetwork.isOnline();
48+
var networkState = JSON.stringify(navigator.connection); //.type
49+
console.log('Internet connectivity chech. NetworkState: ' + networkState);
50+
51+
// HACK: this is a temporary hack due to Android 3G related issue
52+
// described above.
53+
if (navigator.connection.type.toLowerCase() == 'unknown'){
54+
return true;
55+
}else {
56+
return $cordovaNetwork.isOnline();
57+
}
4258
}
4359

4460
return navigator.onLine;
4561
}
4662
});
4763
});
48-
})();
64+
})();

config.xml

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<feature name="InAppBrowser">
4949
<param name="ios-package" value="CDVInAppBrowser"/>
5050
</feature>
51+
<feature name="NetworkStatus">
52+
<param name="android-package" value="org.apache.cordova.NetworkManager" />
53+
</feature>
5154
<preference name="SplashScreen" value="screen"/>
5255
<preference name="SplashScreenDelay" value="3000"/>
5356
<preference name="webviewbounce" value="false"/>

0 commit comments

Comments
 (0)