cordova-plugin-network-information on android retu

2019-07-15 02:07发布

问题:

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");
                  }
        }