我第一次尝试 Apache Cordova 3.0。
下载了 lib,解压了 cordova-android 和 cordova-js 并创建了一个项目:
./create ~/Documents/andriod-projects/HelloWorld com.x.HelloWorld HelloWorld
- OK
res/xml/config.xml
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
在 index.js 设备上准备就绪:
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
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.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert("Network: "+states[networkState]);
}
当我在我的安卓上模拟项目时,我进入了 LogCat Error:Connection is not defined
:
我错过了什么?我必须附加一个 .js 才能声明 Connection?