我正在使用cordova和android平台。
var CORDOVA_JS_BUILD_LABEL = '3.0.0-0-ge670de9';
AVD platform 4.2.2 API level 17
我正在尝试使用连接对象,我将下一个字符串添加到 app/res/xml/config.xml
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />
并将下一个字符串放入 app/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" />
我的代码
onDeviceReady: function() {
var networkState = navigator.connection.type;
alert('networkState = '+networkState);
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('Connection type: ' + states[networkState]);
app.receivedEvent('deviceready');
},
第一次警报的结果:
networkState = 0
代码的其余部分不起作用,似乎对象连接不存在。
我不知道出了什么问题,有人可以帮助我吗?
谢谢。
PS。我用过这个例子http://docs.phonegap.com/en/3.0.0/cordova_connection_connection.md.html#Connection
日志:
06-26 16:00:29.245: D/AndroidRuntime(11703): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
06-26 16:00:29.245: D/AndroidRuntime(11703): CheckJNI is ON
06-26 16:00:29.245: D/dalvikvm(11703): Trying to load lib libjavacore.so 0x0
06-26 16:00:29.255: D/dalvikvm(11703): Added shared lib libjavacore.so 0x0
06-26 16:00:29.255: D/dalvikvm(11703): Trying to load lib libnativehelper.so 0x0
06-26 16:00:29.255: D/dalvikvm(11703): Added shared lib libnativehelper.so 0x0
06-26 16:00:29.295: D/AndroidRuntime(11703): Calling main entry com.android.commands.pm.Pm
06-26 16:00:29.295: D/AndroidRuntime(11703): Shutting down VM
06-26 16:00:29.295: D/dalvikvm(11703): GC_CONCURRENT freed 95K, 18% free 454K/552K, paused 0ms+0ms, total 1ms
06-26 16:00:29.295: D/dalvikvm(11703): Debugger has detached; object registry had 1 entries
06-26 16:00:29.565: D/AndroidRuntime(11715): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
06-26 16:00:29.565: D/AndroidRuntime(11715): CheckJNI is ON
06-26 16:00:29.565: D/dalvikvm(11715): Trying to load lib libjavacore.so 0x0
06-26 16:00:29.565: D/dalvikvm(11715): Added shared lib libjavacore.so 0x0
06-26 16:00:29.565: D/dalvikvm(11715): Trying to load lib libnativehelper.so 0x0
06-26 16:00:29.565: D/dalvikvm(11715): Added shared lib libnativehelper.so 0x0
06-26 16:00:29.605: D/AndroidRuntime(11715): Calling main entry com.android.commands.am.Am
06-26 16:00:29.605: D/dalvikvm(11715): Note: class Landroid/app/ActivityManagerNative; has 156 unimplemented (abstract) methods
06-26 16:00:29.605: I/ActivityManager(1195): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.app/._app} from pid 11715
06-26 16:00:29.605: W/WindowManager(1195): Failure taking screenshot for (246x410) to layer 21010
06-26 16:00:29.625: D/CordovaWebView(11304): CordovaWebView is running on device made by: unknown
06-26 16:00:29.625: D/JsMessageQueue(11304): Set native->JS mode to 2
06-26 16:00:29.645: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.645: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.655: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.675: D/AndroidRuntime(11715): Shutting down VM
06-26 16:00:29.675: D/dalvikvm(11715): GC_CONCURRENT freed 96K, 18% free 483K/584K, paused 0ms+0ms, total 1ms
06-26 16:00:29.675: D/dalvikvm(11715): Debugger has detached; object registry had 1 entries
06-26 16:00:29.675: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.695: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.695: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.745: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.745: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.809: I/Web Console(11304): Could not find cordova.js script tag. Plugin loading may fail. at file:///android_asset/www/phonegap.js:1836
06-26 16:00:29.826: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.826: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:29.855: I/ActivityManager(1195): Displayed com.example.app/._app: +246ms
06-26 16:00:29.965: D/dalvikvm(11304): GC_CONCURRENT freed 403K, 19% free 3472K/4264K, paused 9ms+0ms, total 11ms
06-26 16:00:30.365: E/SurfaceFlinger(794): ro.sf.lcd_density must be defined as a build property
06-26 16:00:30.365: I/Choreographer(11304): Skipped 103 frames! The application may be doing too much work on its main thread.
06-26 16:00:30.375: I/Choreographer(1195): Skipped 59 frames! The application may be doing too much work on its main thread.
06-26 16:00:34.765: D/chromium(11304): Unknown chromium error: -6
06-26 16:00:34.765: D/chromium(11304): Unknown chromium error: -6
06-26 16:00:34.785: E/Web Console(11304): Uncaught ReferenceError: Connection is not defined at file:///android_asset/www/js/index.js:38
06-26 16:00:34.785: E/AudioFlinger(798): no more track names available
06-26 16:00:34.785: E/AudioTrack(1195): AudioFlinger could not create track, status: -12
06-26 16:00:34.785: E/SoundPool(1195): Error creating AudioTrack
06-26 16:00:34.856: W/InputMethodManagerService(1195): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b561e548 attribute=null, token = android.os.BinderProxy@b5613ec0
phonegap 2.9.0 很奇怪,一切正常 有人对 phonegap 3.0.0 有同样的问题吗?