PhoneGap的不是作品的Connection对象 [英] Phonegap not works Connection object

查看:195
本文介绍了PhoneGap的不是作品的Connection对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的科尔多瓦和android平台。

I am using cordova and android platform.

var CORDOVA_JS_BUILD_LABEL = '3.0.0-0-ge670de9';
AVD platform 4.2.2 API level 17

我想使用Connection对象 我说下一个字符串到应用程序/ RES / XML / config.xml中

I am trying to use Connection object I added next string into app/res/xml/config.xml

<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />

和下一个字符串到应用程序/ AndroidManifest.xml中

and next string into 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" />

我的code

my code

    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

result of first alert: networkState = 0

的code不是作品的其余部分,就好像物体连接不存在。

the remaining part of code not works, it seems like object Connection not exists.

我不知道什么是错的,任何人可以帮我吗?

I have no idea what is wrong, can anybody to help me?

感谢。

PS。我用这个例子<一个href="http://docs.phonegap.com/en/3.0.0/cordova_connection_connection.md.html#Connection">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?

Very strange with phonegap 2.9.0 all works perfect Does anybody have the same problem with phonegap 3.0.0 ?

推荐答案

我注意到,您的控制台日志报告

I've noticed that your console log reports

Could not find cordova.js script tag. Plugin loading may fail. at file:///android_asset/www/phonegap.js:1836

这是关于此错误的一个长螺纹: https://github.com/phonegap/phonegap-cli/issues/134

This is a long thread about this error: https://github.com/phonegap/phonegap-cli/issues/134

作为一个临时解决方案,他们建议修改这一行

As a temporary solution they suggest to change this line

<script type="text/javascript" src="phonegap.js"></script>

<script type="text/javascript" src="cordova.js"></script>

index.html中

in index.html

这篇关于PhoneGap的不是作品的Connection对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆