!DOCTYPE html>
<html>
<head>
<title>navigator.connection.type Example</title>
<script type="text/javascript" charset="utf-8" src="js/libs/cordova-2.0.0.js"></script>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
checkConnection();
}
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 type: ' + states[networkState]);
}
</script>
</head>
<body>
<a href="#" onclick="checkConnection();">Just</a>
</body>
</html>
我想在Android手机上获取Internet连接类型 这是我从官方PhoneGap页面引用的代码 它给了我错误 ReferenceError:无法找到变量:文件连接
请帮我摆脱它...
答案 0 :(得分:0)
如果您使用PhoneGap Build来构建应用程序,则必须在head部分中包含Phongap.js标记。象 -
<script src="phonegap.js"></script>
你只需要包含这个标签,就可以使用Phoneap来解决这个问题。
请参阅Phonegap Doc了解网络状况。