3
function checkConnection() {
    var networkState = navigator.connection.type;

    var states = {};
    states[Connection.UNKNOWN] = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI] = 'WiFi connection';
    states[Connection.CELL_2G] = 'Cell 2G connection';
    states[Connection.CELL_3G] = 'Cell 3G connection';
    states[Connection.CELL_4G] = 'Cell 4G connection';
    states[Connection.NONE] = 'No network connection';
    alert(Connection.WIFI);
    alert(navigator.connection.type);
    alert('Connection type: ' + states[networkState]);

}
4

2 回答 2

6

活动结束后你打电话给 checkConnection 了deviceReady吗?

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    checkConnection();
}

在 checkConnection 中只使用navigator.network.connection.type而不是navigator.connection.type因为https://issues.apache.org/jira/browse/CB-1807

于 2012-11-28T14:15:05.520 回答
5

这似乎是科尔多瓦 2.2.0 中的一个错误

https://issues.apache.org/jira/browse/CB-1807

于 2012-11-08T11:41:17.050 回答