There is a problem with Cordova-plugin-network-information on Android. Even if there is a 4G connection, sometimes, when I resume the app from the background and I check connection with navigator.connection.type it returns connection.type = NONE, but there is an internet connection. If I close and re-open the app it returns connection.type = 4G. I user cordova@7.1.0 and cordova-android@6.4.0
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This is the workaround I'm currently using for this issue:
document.addEventListener("resume", function(){
navigator.connection.getInfo(function(type){
navigator.connection.type = type;
});
}, false);
See CB-14132 for an explanation of why.
回答2:
Try to use
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
if(navigator.onLine) {
alert("Internet Connect");
}else {
alert("No Internet");
}
}