cordova-plugin-network-information on android return connection.type = NONE even if there is 4G connection

跟風遠走 提交于 2019-12-11 03:08:36

问题


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


来源:https://stackoverflow.com/questions/48024891/cordova-plugin-network-information-on-android-return-connection-type-none-even

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!