[英]cordova-plugin-network-information on android return connection.type = NONE even if there is 4G connection
Android 上的 Cordova-plugin-network-information 存在問題。 即使有 4G 連接,有時,當我從后台恢復應用程序並檢查與 navigator.connection.type 的連接時,它會返回 connection.type = NONE,但有互聯網連接。 如果我關閉並重新打開應用程序,它會返回 connection.type = 4G。 我用戶cordova@7.1.0和cordova-android@6.4.0
這是我目前用於此問題的解決方法:
document.addEventListener("resume", function(){
navigator.connection.getInfo(function(type){
navigator.connection.type = type;
});
}, false);
有關原因的解釋,請參閱CB-14132 。
嘗試使用
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
if(navigator.onLine) {
alert("Internet Connect");
}else {
alert("No Internet");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.