【问题标题】:cordova-plugin-network-information on android return connection.type = NONE even if there is 4G connectionandroid上的cordova-plugin-network-information返回connection.type = NONE即使有4G连接
【发布时间】:2018-06-13 19:15:42
【问题描述】:
Android 上的 Cordova-plugin-network-information 存在问题。即使有 4G 连接,有时,当我从后台恢复应用程序并使用 navigator.connection.type 检查连接时,它会返回 connection.type = NONE,但有互联网连接。如果我关闭并重新打开应用程序,它会返回 connection.type = 4G。我用户 cordova@7.1.0 和 cordova-android@6.4.0
【问题讨论】:
标签:
android
cordova
connection
【解决方案1】:
这是我目前用于解决此问题的解决方法:
document.addEventListener("resume", function(){
navigator.connection.getInfo(function(type){
navigator.connection.type = type;
});
}, false);
请参阅 CB-14132 了解原因。
【解决方案2】:
尝试使用
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
if(navigator.onLine) {
alert("Internet Connect");
}else {
alert("No Internet");
}
}